【问题标题】:Regular expression re2 grouping (and/or operators)正则表达式 re2 分组(和/或运算符)
【发布时间】:2018-03-05 16:59:09
【问题描述】:

我正在努力获得用于对纬度和经度范围进行分组的正确正则表达式。我正在使用我相信使用 re2 的 Google Data Studio 过滤器。这些在 URL 中给出,所以我试图只过滤掉我感兴趣的不规则形状域中的纬度/经度对。如果它是一个方形域,我可以很容易地做到这一点,因为有一组lat 对应一组 lon。

这是我想做的:

If latitude is in this range: Latitude 39\.[4-9]|Latitude 40\.[0-9]|Latitude 41\.[0-5]  AND longitude is in this range: Longitude 80\.[0-5]|Longitude 79\.[0-9]  (then capture these URLs)

如果

latitude is in this range: Latitude 40\.[0-7]|Latitude 39\.[6-9] AND longitude in this range: Longitude 82\.[2-9]|Longitude 81\.[0-9]|Longitude 80\.[0-5] (then capture these URLs)

以下是我应该能够做到的感觉,但语法不起作用:

((Latitude 39\.[4-9]|Latitude 40\.[0-9]|Latitude 41\.[0-5]) & (Longitude 80\.[0-5]|Longitude 79\.[0-9]))|((Latitude 40\.[0-7]|Latitude 39\.[6-9])&(Longitude 82\.[2-9]|Longitude 81\.[0-9]|Longitude 80\.[0-5]))

我知道 Data Studio 正则表达式可以使用管道/或符号,但我确实需要 &/and 符号来完成这项工作,但我认为我不能使用该符号。

我尝试了很多不同的组合,但我无法在 Data Studio 过滤器中完全正确。感谢您的帮助。

【问题讨论】:

  • 你能举一个输入格式的例子吗?
  • 当然,这是我正在尝试分组的 URL 标题(按页面标题过滤)的示例,等待纬度/经度。 “预测纬度 42.36(度符号)N 和经度 122.95(度符号)W”。谢谢!

标签: regex google-data-studio re2


【解决方案1】:

我想我明白了。我需要将纬度和经度组合成一个正则表达式,然后使用谷歌的Data Studio选项使用“或”,然后放入下一个表达式。

这是两个表达式,它们通过 .{2,3} 部分计算纬度和经度(如果存在)的第二个小数点。

.+for Latitude (39\.[4-9]|40\.[0-9]|41\.[0-5]).{2,3} and Longitude (80\.[0-5]|79\.[0-9]).+

.+for Latitude (40\.[0-7]|39\.[6-9]).{2,3} and Longitude (82\.[2-9]|81\.[0-9]|80\.[0-5]).+

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-28
    • 2012-10-30
    • 1970-01-01
    • 1970-01-01
    • 2013-10-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多