I'm using this regex:
([\w\s]+)(=|!=)([\w\s]+)( (or|and) ([\w\s]+)(=|!=)([\w\s]+))*
to match a string such as this: i= 2 or i =3 and k!=4
When I try to extract values using m.group(index), I get:
(i, =, 2, **and k!=4**, and, k, ,!=, 4).
Expected output: (i, =, 2, or, i, =, 3, and, k , !=, 4) How do i extract the values correctly?
P.S. m.matches() returns true.
you are trying to match with a regexp on an expression...you might want to use a parser, because this regexp (when you have it) can't be extended further..but a parser can be extended at any time
for example, consider using antlr (ANTLR: Is there a simple example?)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With