0

Okay so I need to create an advance filter in Google Analytics that includes "breast", but DOES NOT include "before" "after" or "blog" in the url. I also want to filter out .jpg file extensions.

Here are example URLs that I want the filter to return: http://www.doctortaylor.com/breast-lift-surgery/ http://www.doctortaylor.com/breast-augmentation-pasadena-and-los-angeles-area/

I want to filter out any urls that are before and after photo pages, and any actual .jpg file urls.

I'm a regex beginner, but this is pretty advanced. Any help would be greatly appreciated!!

1 Answers1

1

This regular expression does fairly well:

^(?!before|after|blog)*((?!before|after|blog).)*breast(?!before|after|blog|\.jpg)*((?!before|after|blog|\.jpg).)*$

UPDATED: I have updated the expression to capture all scenarios, even characters that begin or end the string. This regular expression excludes all words that you list in your description and correctly identifies the word breast.

MATCHES

http://www.doctortaylor.com/breast-lift-surgery/
http://www.doctortaylor.com/breast-augmentation-pasadena-and-los-angeles-area/

DOES NOT MATCH

http://www.doctortaylor.com/breast-lift-surgeryblog/
http://www.doctortaylor.com/breast-lift-surgery.jpg/
http://blog.doctortaylor.com/breast-lift-surgery/
http://www.doctortaylor.com/after-breast-lift-surgery/

This regular expression uses an equivalent of inverse matching.

Community
  • 1
  • 1
πόδας ὠκύς
  • 10,303
  • 2
  • 32
  • 42
  • Awesome! Thank you. This helps a lot! – tayvansickle Jan 08 '14 at 18:25
  • Actually, I just entered it in to the "extraction" option in Google Analytics Content grouping and it said that the Regular Expression was invalid... – tayvansickle Jan 08 '14 at 18:33
  • @tayvansickle Interesting. The regex tester suggested by Google Analytics [here](https://support.google.com/analytics/answer/2936903?hl=en) (Rubular, near the bottom) indicates that the above regular expression works just fine. Moreover, the regex is safe for javascript (which often has limitations), which I tested [here](http://www.regular-expressions.info/javascriptexample.html). Perhaps Google Analytics has limited regex capabilities? You might just want to make sure you captured the whole regex above just to be sure it doesn't work. I've successfully tested it in three different languages. – πόδας ὠκύς Jan 08 '14 at 23:31