【问题标题】:Regex Data Studio exclude URL parameters正则表达式数据洞察排除 URL 参数
【发布时间】:2021-03-26 14:41:44
【问题描述】:

我已经设法在 Google Data Studio 上使用正则表达式来创建一个“最后路径”目录值,该值很好用,使用;

REGEXP_EXTRACT( Page , '.*/(.*)/' )

是否可以排除带参数的网址?

所以例如正则表达式匹配;

/目录1/

/directory1/?var=1

/directory1/?var=2

所以我希望排除任何 ?var= URL,但不限于 var 参数值。

感谢任何帮助。

【问题讨论】:

  • REGEXP_EXTRACT( Page , '.*/(.*)/$' )?
  • 感谢您的回复,但它返回 null 所以不起作用...
  • 我认为你在正确的轨道上但是没有匹配一次?包含在字符串中
  • proof 它有效。它不会吞噬问号。
  • 您说得对,谢谢,一些排名靠前的流量结果被取消了,但在更下方它收集了正确的结果。谢谢!

标签: regex google-data-studio re2


【解决方案1】:

要解决当前问题,请使用

REGEXP_EXTRACT( Page , '.*/(.*)/$' )

锚点$ 停止匹配/ 之后包含更多文本的任何内容。如果有查询字符串,则不会发生匹配。

说明

--------------------------------------------------------------------------------
  .*                       any character except \n (0 or more times
                           (matching the most amount possible))
--------------------------------------------------------------------------------
  /                        '/'
--------------------------------------------------------------------------------
  (                        group and capture to \1:
--------------------------------------------------------------------------------
    .*                       any character except \n (0 or more times
                             (matching the most amount possible))
--------------------------------------------------------------------------------
  )                        end of \1
--------------------------------------------------------------------------------
  /                        '/'
--------------------------------------------------------------------------------
  $                        before an optional \n, and the end of the
                           string

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-06
    • 2016-07-23
    • 1970-01-01
    • 1970-01-01
    • 2021-06-27
    • 2018-11-28
    • 2022-07-22
    • 2020-07-12
    相关资源
    最近更新 更多