最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Using Regular Expressions to match single equals sign only - Stack Overflow

programmeradmin0浏览0评论

I'm attempting to build a regular expression (in JavaScript) that would match = but not !=, <=, >=, '= and ==. I've figured out everything but ==:

text.match(/[^!<>']=/) != null

I've failed everything I've tried to ignore ==. Would anyone be able to help?

I'm attempting to build a regular expression (in JavaScript) that would match = but not !=, <=, >=, '= and ==. I've figured out everything but ==:

text.match(/[^!<>']=/) != null

I've failed everything I've tried to ignore ==. Would anyone be able to help?

Share Improve this question asked Jul 29, 2013 at 22:59 eliajfeliajf 4957 silver badges16 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 3

You could use something like this, which also allows the equal sign to be at the very beginning or at the very end of your string:

/(^|[^!><'=])=($|[^=])/

but note that the matching result will contain the characters to the left and to the right of the equal sign, if there are any.

text.match(/[^=<>!']=[^=]/)
发布评论

评论列表(0)

  1. 暂无评论