RegEx help matching operators
I need to match some operators: =, !=, >, <, <=, >= The string I need to match may be something like: "2=2 OR 33 >= 32 AND 3<5"
What can be the RegEx expression to match this, knowing that - I don't want to receive a '=' match on a '<=' operator - The operators may or may not have开发者_开发百科 spaces surrounding them
Thanks in advance! Alex
Try this:
(<=|>=|!=|=|>|<)
This seems to work:
[<>!]?=|[<>]
It takes: <
, >
or !
before =
(or just =
),
OR: <
or >
on their on.
That said, for a bit more complexity you'll probably need a parser (e.g. if you wanted to support parentheses)
My proposal: [<>]=?|[!=]?=
. Matches any of = != > < <= >= ==
.
[^?!><=]+\s*(?<operator>[><!]?=|[><])\s*[^?!><=]+
+ ExplicitCapture
filters >>
or ===
or == ==
Are you also trying to get the numbers?if so. . .
/[0-9]+[ ]*(<=|>=|!=|=|>|<)[ ]*[0-9]+/
...anything in the range of 0-9 one or more times, followed by 0 or more spaces followed by your operator, 0 or more spaces and anything in the range of 0-9 one or more times.
This will get the number and the operator
精彩评论