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 02 Answers
Reset to default 3You 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(/[^=<>!']=[^=]/)