Reputation: 1314
In a C# class, I came across this regular expression:
<?>?=?\d{4}
It is pretty obvious that its last part (\d{4}
) matches 4 decimal digits but what about <?>?=?
? What does it match?
Thanks for any explanations.
Upvotes: 0
Views: 873
Reputation: 700252
The question mark after the characters make it optional, so it matches any combination where each character can be present or not:
It's probably meant to match any of the three characters on its own, but then you would rather use [<>=]?
instead.
Upvotes: 2
Reputation: 301117
Four digits at the end preceded by the <
, >
and =
occurring zero or once in that order.
Match:
<>=1234
>=1234
=1234
1234
<=1234
Upvotes: 4
Reputation: 39197
The expression '<?>?=?'
matches a '<' char (or none) possibly followed by a '>' possibly followed by a '='. Thus all of the following will match:
Upvotes: 3