正则表达式 - 匹配包含这些词中的 1 个或 2 个但不是全部 3 个的 URL

Regex - Match URLs which contain 1 or 2 of these words but not all 3

我正在为 Google Analytics 构建正则表达式,我快完成了,但我卡在了最后一部分。

我正在尝试匹配 URL 中的特定单词,不管它们的顺序如何,但我想排除同时包含 3 个特定单词的 URL。

这里有 4 个 URL:

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

我希望我的正则表达式匹配以上所有 URL,除了第一个(包含 sony、phillips 和 magnavox)。品牌可以有不同的顺序,因此无论顺序如何,都需要检查这 3 个词是否存在。

这是我当前的正则表达式,它匹配所有这些 URLs:

(find-store.*sony.*magnavox)|(find-store.*sony.*phillips)|(find-store.*sony)

这个正则表达式有效。 ^(?!(?=.*sony)(?=.*phillips)(?=.*magnavox)).+$

 ^                          # BOS
 (?!                        # Cannot be all three on the line
      (?= .* sony )
      (?= .* phillips )
      (?= .* magnavox )
 )
 .+ 
 $                          # EOS

对于特定的短语 ^(?!(?=.*sony)(?=.*phillips)(?=.*magnavox)).*find-store.*$

 ^                          # BOS
 (?!                        # Cannot be all three on the line
      (?= .* sony )
      (?= .* phillips )
      (?= .* magnavox )
 )
 .* 
 find-store                 # Add sepcific phrase/words
 .* 
 $                          # EOS

您也可以将特定短语放在顶部

 # ^.*?find-store(?!(?=.*sony)(?=.*phillips)(?=.*magnavox)).+$

 ^                          # BOS
 .*? 
 find-store                 # Add sepcific phrase/words

 (?!                        # Cannot be all three on the line
      (?= .* sony )
      (?= .* phillips )
      (?= .* magnavox )
 )
 .+ 
 $                          # EOS

如果你需要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