use*_*286 0 regex google-analytics
我正在为Google Analytics构建一个正则表达式,我几乎就在那里,但我仍然坚持到最后一部分.
我正在尝试匹配网址中的特定字词,无论其顺序如何,但我想排除包含3个特定字词的网址.
这是4个网址:
/find-store?radius=30&manufacturers=sony,phillips,magnavox&segment=residential&postal=998028#
/find-store?search=Juneau%2C+AK+99802%2C+USA&radius=30&manufacturers=sony,magnavox&segment=commercial&postal=998028#
/find-store?radius=30&manufacturers=phillips,sony&segment=residential&postal=998028#
/find-store?radius=30&manufacturers=magnavox&segment=residential&postal=998028#
Run Code Online (Sandbox Code Playgroud)
我希望我的正则表达式匹配所有上述URL,除了第一个(包含sony,phillips和magnavox).品牌可以按不同顺序排列,因此无论订单如何,都需要检查这3个字是否存在.
这是我当前正则表达式匹配所有这些URL:
(find-store.*sony.*magnavox)|(find-store.*sony.*phillips)|(find-store.*sony)
Run Code Online (Sandbox Code Playgroud)
小智 6
这个正则表达式有效. ^(?!(?=.*sony)(?=.*phillips)(?=.*magnavox)).+$
^ # BOS
(?! # Cannot be all three on the line
(?= .* sony )
(?= .* phillips )
(?= .* magnavox )
)
.+
$ # EOS
Run Code Online (Sandbox Code Playgroud)
对于特定的短语 ^(?!(?=.*sony)(?=.*phillips)(?=.*magnavox)).*find-store.*$
^ # BOS
(?! # Cannot be all three on the line
(?= .* sony )
(?= .* phillips )
(?= .* magnavox )
)
.*
find-store # Add sepcific phrase/words
.*
$ # EOS
Run Code Online (Sandbox Code Playgroud)
您也可以将特定短语放在顶部
# ^.*?find-store(?!(?=.*sony)(?=.*phillips)(?=.*magnavox)).+$
^ # BOS
.*?
find-store # Add sepcific phrase/words
(?! # Cannot be all three on the line
(?= .* sony )
(?= .* phillips )
(?= .* magnavox )
)
.+
$ # EOS
Run Code Online (Sandbox Code Playgroud)
如果您需要sony,phillips或magnovox,您可以在底部添加它们.
# ^.*?find-store(?!(?=.*sony)(?=.*phillips)(?=.*magnavox)).*?(sony|phillips|magnavox).*?$
^ # BOS
.*?
find-store # Add required sepcific phrase/words
(?! # Cannot be all three on the line
(?= .* sony )
(?= .* phillips )
(?= .* magnavox )
)
.*?
( sony | phillips | magnavox ) # (1), Required. one of these
.*?
$ # EOS
Run Code Online (Sandbox Code Playgroud)