问题描述
我正在 Google Analytics 中设置一些目标,可以使用一些正则表达式帮助.
I'm setting up some goals in Google Analytics and could use a little regex help.
假设我有 4 个网址
http://www.anydotcom.com/test/search.cfm?metric=blah&selector=size&value=1
http://www.anydotcom.com/test/search.cfm?metric=blah2&selector=style&value=1
http://www.anydotcom.com/test/search.cfm?metric=blah3&selector=size&value=1
http://www.anydotcom.com/test/details.cfm?metric=blah&selector=size&value=1
我想创建一个表达式来识别包含字符串 selector=size 但不包含 details.cfm
I want to create an expression that will identify any URL that contains the string selector=size but does NOT contain details.cfm
我知道要找到一个不包含另一个字符串的字符串,我可以使用这个表达式:
I know that to find a string that does NOT contain another string I can use this expression:
(^((?!details.cfm).)*$)
但是,我不确定如何添加 selector=size 部分.
But, I'm not sure how to add in the selector=size portion.
任何帮助将不胜感激!
推荐答案
应该这样做:
^(?!.*details.cfm).*selector=size.*$
^.*selector=size.*$
应该够清楚了.第一位,(?!.*details.cfm)
是一个否定的前瞻:在匹配字符串之前,它检查字符串不包含details.cfm"(前面有任意数量的字符)它).
^.*selector=size.*$
should be clear enough. The first bit, (?!.*details.cfm)
is a negative look-ahead: before matching the string it checks the string does not contain "details.cfm" (with any number of characters before it).
这篇关于包含一个词但不包含另一个词的字符串的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!