admin管理员组

文章数量:1394217

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(/[^=<>!']=[^=]/)

本文标签: javascriptUsing Regular Expressions to match single equals sign onlyStack Overflow