2

I'm working with Google Analytics API add-on for Google Spreadsheets to pull in data.

I know basic regex and it turns out that negative lookbacks / not operators (I'm assuming they're the same?) aren't allowed in Google Analytics, therefore I'm having difficulty with this filter.

I want to filter out all URL page paths that have a query string in them. Here's a sample list:

/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

I want my output to be:

/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

This is the start of my Regex...

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

...which ignores the fourth line but I have no idea what to put after the second backslash.

I've tried a few things here (like this one Regular expression to stop at first match) and have been testing my code here (http://www.analyticsmarket.com/freetools/regex-tester).

Any insight would be greatly appreciated!

Community
  • 1
  • 1
dn_nicholson
  • 29
  • 1
  • 8

3 Answers3

0

You can use the following regular expression to match the desired output.

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

Live Demo

hwnd
  • 65,661
  • 4
  • 77
  • 114
0

Try this also. It will strictly capture. what you need.

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

SEE DEMO : http://regex101.com/r/gS3lF8/2

depsai
  • 385
  • 1
  • 13
0
^/product/\d+/[a-zA-Z0-9-]+$

You can try this.See demo.

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

vks
  • 63,206
  • 9
  • 78
  • 110
  • Thanks for your help. I went with another answer just because there MAY be a situation where the first directory could be something else. Not currently, but just in case. – dn_nicholson Nov 26 '14 at 15:56