I have a text input containing lots of operators, variable and English words. From this input I have to separate all the operators alone.
As of now I’m using regular expression matching, so the number of operators matched depends on the regular expression. problem I get are ‘= is matched with <=’, ‘& is matched with &&’. I need to match both = and <= separately.
Is there any better way for matching the operators other than regex?
There probably is. But as an alternative, you could have your regex as (e.g.):
(Modify to your specifications – not sure if you want addition, subtraction,
++for incrementing etc too).The
+means “one or more” and so the regex matches as many characters as possible, meaning that if<=is in the text, it will match<=rather than<and then=.Then, only once you’ve extracted all the matches, loop through them all and classify them.