Mun*_*ish 18 regex regex-negation
我想匹配&符号(&),但不是当它以下列方式存在时
'
"
>
<
&
&#
Run Code Online (Sandbox Code Playgroud)
所以在以下行中
& MY& NAME IS M&Hh. ' " > < & &# &&&&&&
我希望它匹配除了存在的所有&符号之外的所有&符号
' " > < & &#
Tim*_*ker 28
这看起来像负面前瞻断言的工作:
&(?!(?:apos|quot|[gl]t|amp);|#)
Run Code Online (Sandbox Code Playgroud)
应该管用.
说明:
& # Match &
(?! # only if it's not followed by
(?: # either
apos # apos
|quot # or quot
|[gl]t # or gt/lt
|amp # or amp
); # and a semicolon
| # or
\# # a hash
) # End of lookahead assertion
Run Code Online (Sandbox Code Playgroud)