使用Regex过滤Google AnalyticsAPI - 在字符前停止(查询字符串)

时间:2014-11-26 04:04:26

标签: regex google-analytics

我正在使用Google Spreadsheets的Google AnalyticsAPI插件来提取数据。

我知道基本的正则表达式,结果是负面的回顾/不是运算符(我假设它们是相同的?)在Google Analytics中是不允许的,因此我对此过滤器有困难。

我想过滤掉所有包含查询字符串的网页路径。这是一个示例列表:

/product/9779/this-is-a-product
/product/27193/this-is-a-product-with-a-query-string?productId=50334&ps=True
/product/281727/this-is-another-product-with-a-really-long-title
/product/979
/product/979/product-12-pump-septic
/product/9790/the-1983-ford-sedan
/product/9791/remington-870-3-express-410-pump-shotgun
/category/2738/this-is-a-category

我希望我的输出为:

/product/9779/this-is-a-product
/product/281727/this-is-another-product-with-a-really-long-title
/product/979/product-12-pump-septic
/product/9790/the-1983-ford-sedan
/product/9791/remington-870-3-express-410-pump-shotgun

这是我的正则表达式的开始...

ga:pagePath=~^/product/(.*)/

...忽略第四行,但我不知道在第二次反斜杠后要放什么。

我在这里尝试了一些事情(比如这个Regular expression to stop at first match),并在此处测试我的代码(http://www.analyticsmarket.com/freetools/regex-tester)。

非常感谢任何见解!

3 个答案:

答案 0 :(得分:0)

您可以使用以下正则表达式来匹配所需的输出。

^/product/.*/[\w-]+$

Live Demo

答案 1 :(得分:0)

也试试这个。它将严格捕获。你需要什么。

^\/product\/((?:(?!\/|[a-z]).)*)\/[\w-]+$

查看演示: http://regex101.com/r/gS3lF8/2

答案 2 :(得分:0)

^/product/\d+/[a-zA-Z0-9-]+$

你可以尝试一下。参见演示。

http://regex101.com/r/oE6jJ1/16