I’m using Javascript regex functions to split expressions like:
var1=32
var2<var4
var1!=var3
I’m using this regex:
/^(.*)([=|!=|<|>])(.*)$/ig
It works pretty well except with the != (different) operator. What’s the problem?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The problem is you are using a character class instead of an alternation. The expression
[=|!=|<|>]is equivalent to[<>=!|]. Remove the[and]to get what you want.I’ve also changed the first (.*) to be non-greedy so that it doesn’t consume the
!in!=. If you know that the left and right expressions will always contain (for example) only alphanumeric characters only, it would be better to specify that instead of matching with the dot.