Negative lookahead alternative

1.3k Views Asked by At

For a URL pattern such as this one:

/detail.php?a=BYGhs5w8e9o&b=234844617545&h=9827a

I would like Google Analytics to match only the URL's with the a and b parameters in it:

/orderdetail.php?a=BYGhs5w8e9o&b=234844617545

And thus strip out:

&h=9827a

The main goal is to be able to setup a goal in Google Analytics which covers only the a and b parameters and ignores the h parameter.

Is there an easy way to accomplish this without a negative lookahead?

1

There are 1 best solutions below

0
On

Standard regular expressions do not need negative lookahead for this. Just do a match and replace. Searching for:

(/detail.php\?a=\w+&b=\w+)&h=\w+

and replacing with \1 works with the regular expressions in Notepad++ version 6.5.5. Google's regular expressions may be subtly different.

The above works by surrounding the wanted text with capturing braces and leaving the unwanted part outside. The ? needs escaping as un-escaped it means the previous item (ie the p) is optional. The \w sequence mean any "word" character so \w+ means a word.