patel.milanb
patel.milanb

Reputation: 5992

need regular expression to match dynamic url to setup goal in Google Analytics

I need to match complete dynamic URL to set-up as a goal in Google Analytics. I don't know how to do that. I have searched on Google with no luck.

So here is the case.

When pressed enter button, the goal URL would be different depending on the product selected.

Example:

http://www.somesite.com/footwear/mens/hiking-boots/atmosphere-boot-p7023.aspx?cl=BLACK

http://www.somesite.com/womens/clothing/waterproof-jackets/canyon-womens-long-jacket-p7372.aspx?cl=KHAKI

http://www.somesite.com/travel/accessories/mosquito-nets/mosquito-net-double-p5549.aspx?cl=WHITE

http://www.somesite.com/ski/accessories/ski-socks-tubes/ski-socks-p2348.aspx?cl=BLACK

If you look closely in the URL, you can see that there are three parts:

http://www.somesite.com/{ 1st part }/{ 2nd part }/{3rd part }/{ page URL }/{ querystring param}

So if I manually change page URL part like p2348 to p1234, website will redirect to the proper page:

http://www.somesite.com/kids/clothing/padded-down-jackets/khuno-kids-padded-jacket-p1234.aspx?cl=BLUE

I don't know how to do that. Please help with regular expression to match those 4 digit while p remains there OR help me with those three parts matching any text/number and then 4 digit product code.

Upvotes: 0

Views: 1048

Answers (2)

Nikola Malešević
Nikola Malešević

Reputation: 1858

You should try this regex. It's the most simple one and functional as well.

p\d{4}

This will return you strings like p7634, p7351, p0872.

If you are not completely sure there will be exactly 4 digits, use the following regex.

p\d*

This one will return you strings like p43, p9165, p012, p456897689 and others.

Upvotes: 2

tomsv
tomsv

Reputation: 7277

Try

p[0-9][0-9][0-9][0-9]\.aspx

if there are always 4 digits after the p.

Your attempt

 [^p]\d[0-9][0-9]

does not work because [^p] matches anything except for p, and \d[0-9][0-9] matches only three digits instead of four.

Upvotes: 1

Related Questions