Use the expression [<>]=? number
.
[<>]
means either <
or >
.
=?
is an optional =
sign.
Pregunta
I have the following JS var:
var tokens = str.match(/\[|\]|< number|\)|and |(?:(?!and )[^\[\]])+/g);
tokens
is later used in a switch()
statement.
This matches occurrences of:
[
]
< number
)
and
(with a space at the end)However, I would like to precede number
not only by <
but possibly also by other operators. The following are needed:
>
>=
<
<=
So match
also has to look for < number
, <= number
, > number
, >= number
. Is there a quick and easy way to do this by, for instance, defining a wildcard/variable for the possible operators?
Solución
Use the expression [<>]=? number
.
[<>]
means either <
or >
.
=?
is an optional =
sign.