I would like to match any one of these characters: <
or >
or <=
or >=
or =
.
This one doe
I'm not sure why you are using slashes (might have something with coldfusion that I'm not aware of, add them back if need be)... Your regex currently matches only one character. Try:
[<=>]{1,2}
If you want one regex to match only >
, <
, >=
, <=
and =
, there will be a bit more to that. The REMatch() function in coldfusion will return all the matched results in an array, so it's important to specify delimiters or boundaries in one way or another, because it's like a findall
in python, or preg_match_all
in PHP (or flagging the global match).
The boundary I think is the simplest is the \b
:
\b(?:[<>]=?|=)\b
Here's a demo with g activated.
And without these boundaries, here's what happens.
EDIT: Didn't realise something about the spaces. Could perhaps be fixed with this?
\b\s*(?:[<>]=?|=)\s*\b
You don't need to escape any of those characters in character class. Apart from that, you need to use quantifiers, to match more than 1 repetition of those characters.
You need this:
[<>=]{1,2}
Note the quantifier, to match 2 repetitions, as required for <=
and >=
.
Also, note that this will also match - ==
, <<
. If you strictly want to match just those 4 strings, you can use this regex:
[<>]=?|=
Using ?
after =
makes it optional. So, first part will match - <
, >
, <=
, and >=
. And then we add =
using pipe.
Try this:
[<>]=?|=
It matches <
or >
optionally followed by =
, or just =
by itself.