tags:

views:

52

answers:

3

I have the pages that I want to set as a goal in Google Analytics but there is a part of the URL that is dynamic number (3 integers). How do I specify such a URL with regex?

URLs are:

/info.php?id=XXX&sent=ok

I am using this regular expression

/info.php?id=^[0-9]{3}$&sent=ok

But it is not working.

What is wrong?

+3  A: 

Remove the ^ and $ parts. They refer to the beginning and ending of the string, and you have them right in the middle, so nothing can possibly match that expression.

Also the ? symbol is a reserved operator in regular expressions. It means the preceding item is optional. You'll want to escape it by replacing it with \?.

Welbog
Don’t forget the dot.
Gumbo
Thanks a lot all of you. It is working.
Jancek
A: 

you're using ^ and $ which match beginning and end of the line, respectively. this should work:

/info\.php\?id=[0-9]{3}&sent=ok
SilentGhost
why the downvote?
SilentGhost
+1  A: 

You should escape any regex reserved characters like ?. also the $ is usually a line ending in regex, as well as ^ being a line beginning, so yours would fail. Something closer to :

/info\.php\?id=[0-9]{3}&sent=ok

might do the trick

akf