= 32 AND 3<5\"" />
开发者

RegEx help matching operators

开发者 https://www.devze.com 2022-12-19 10:08 出处:网络
I need to match some operators: =, !=, >, <, <=, >= The string I need to match may be something like: \"2=2 OR 33 >= 32 AND 3<5\"

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

0

精彩评论

暂无评论...
验证码 换一张
取 消