Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
任何人都有一个好的正则表达式来匹配==,!=但不是===(!==我打算用它作为对javascript代码的简单检查)?
==
!=
===
!==
我试过[^=]==[^=]了,但这在字符串的开头和结尾都失败了。
[^=]==[^=]
如果您的正则表达式引擎完全支持环视断言(例如,.NET),则使用
(?<![!=])[!=]=(?!=)
如果不是(JavaScript!),则需要在匹配之前显式处理字符:
(?:^|[^!=])([!=]=)(?!=)
尝试使用以下内容:
[^=!]([=!]=)[^=]
http://rubular.com/r/Db8fv6RQht