我希望从匹配的中排除任何指向扩展名为".log"的文件或包含目录"tmp"的路径的路径字符串
我快到了:
(?!tmp).+?.(?!log|tmp).+
http://rubular.com/r/Ubkz7MIEGH
我想要的是
tmp/hello.jpg
以与相同的方式排除
hello.log
hmm.tmp
被排除在外。
只需尝试以下正则表达式:
^(?!(?:.*log$)|tmp).*$
怎么样:
^(?!.*btmpb)(?!.+.logb)(.+)$
解释:
The regular expression:
(?-imsx:^(?!.*btmpb)(?!.+.logb)(.+)$)
matches as follows:
NODE EXPLANATION
----------------------------------------------------------------------
(?-imsx: group, but do not capture (case-sensitive)
(with ^ and $ matching normally) (with . not
matching n) (matching whitespace and #
normally):
----------------------------------------------------------------------
^ the beginning of the string
----------------------------------------------------------------------
(?! look ahead to see if there is not:
----------------------------------------------------------------------
.* any character except n (0 or more times
(matching the most amount possible))
----------------------------------------------------------------------
b the boundary between a word char (w)
and something that is not a word char
----------------------------------------------------------------------
tmp 'tmp'
----------------------------------------------------------------------
b the boundary between a word char (w)
and something that is not a word char
----------------------------------------------------------------------
) end of look-ahead
----------------------------------------------------------------------
(?! look ahead to see if there is not:
----------------------------------------------------------------------
.+ any character except n (1 or more times
(matching the most amount possible))
----------------------------------------------------------------------
. '.'
----------------------------------------------------------------------
log 'log'
----------------------------------------------------------------------
b the boundary between a word char (w)
and something that is not a word char
----------------------------------------------------------------------
) end of look-ahead
----------------------------------------------------------------------
( group and capture to 1:
----------------------------------------------------------------------
.+ any character except n (1 or more times
(matching the most amount possible))
----------------------------------------------------------------------
) end of 1
----------------------------------------------------------------------
$ before an optional n, and the end of the
string
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------
^(?!tmp).*(?<!.tmp|log)$
这只是一个消极的背后。实时演示