Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
864 views
in Technique[技术] by (71.8m points)

regex - RegExp alternative to negative lookahead match for Google Analytics

I'm setting up some conversion funnels on Google Analytics. One is to analyse traffic going from the main site to a secondary promotional site running on a virtual directory (on the same domain though)

I should add, this is a setup form in Google Analytics, I can't using another other code (PHP, JS, C# etc) and it has to be done in one step

So for example something like:

  • /default.aspx or /directory/default.aspx or /somedirname/default.aspx
  • [to >]
  • /promotion/default.aspx

In regular expression land, this would be:

  • ^/(?!promotion)(.*).aspx
  • [to >]
  • ^/promotion/(.*).aspx

The problem is Google Analytics no longer supports negative lookaheads, so the regexp ^/(?!promotion)(.*).aspx fails. (Reference here, first reply)

Is there another way I can do this?

Many thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You could do a two-step approach (whether that's possible in Analytics, I have no idea, though):

  1. Replace unconditionally:
    /(.*.aspx) --> /promotion/$1
  2. Replace again:
    /promotion/promotion/(.*) --> /promotion/$1

If all else fails:

^/(?:[^p]|p[^r]|pr[^o]|pro[^m]|prom[^o]|promo[^t]|promot[^i]|promoti[^o]|promotio[^n])/(.*).aspx

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...