需要使用正则表达式来匹配动态网址以在Google Analytics中设置目标

时间:2021-12-08 15:21:57

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.

我需要将完整的动态网址设置为Google Analytics中的目标设置。我不知道该怎么做。我在Google上搜索没有运气。

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/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/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/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

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:

如果仔细查看URL,可以看到有三个部分:

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

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:

因此,如果我手动将页面URL部分(如p2348)更改为p1234,则网站将重定向到正确的页面:

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

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.

我不知道该怎么做。请帮助使用正则表达式来匹配那些4位数而p仍然存在或者帮助我处理那些匹配任何文本/数字和4位数产品代码的三个部分。

2 个解决方案

#1


1  

Try

尝试

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

if there are always 4 digits after the p.

如果p之后总是有4位数字。

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.

不起作用,因为[^ p]匹配除p以外的任何内容,\ d [0-9] [0-9]只匹配三位数而不是四位数。

#2


2  

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.

这将返回像p7634,p7351,p0872这样的字符串。

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

如果您不完全确定将有4位数,请使用以下正则表达式。

p\d*

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

这个将返回你的字符串,如p43,p9165,p012,p456897689等。

#1


1  

Try

尝试

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

if there are always 4 digits after the p.

如果p之后总是有4位数字。

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.

不起作用,因为[^ p]匹配除p以外的任何内容,\ d [0-9] [0-9]只匹配三位数而不是四位数。

#2


2  

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.

这将返回像p7634,p7351,p0872这样的字符串。

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

如果您不完全确定将有4位数,请使用以下正则表达式。

p\d*

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

这个将返回你的字符串,如p43,p9165,p012,p456897689等。