I'm trying to test a string against this pattern: "At least one square bracket pair, wrapping 2 digits, followed by at lease one character". For example, [11][22][33]dd
should match while [11][22][33]
shouldn't.
I've tried this regex: (\[\d{2}])+.+
. However, when it is tested against with [11][22][33]
, which should have failed, it still passes that test. The first +
quantifier only matches two groups [11]
and [22]
, while the rest part [33]
is matched by .+
.
I thought the "greedy" behaviour of the +
quantifier would exhaust all the matching segments of the group it modifies; however it seems that the regex engine would place the "exhaust all matching possibilities" principle above the "greedy quantifier" rule, not the way I'd expected.
How should I achieve my goal?
(This question is actually language-agnostic, though tagged with "golang" which is the language I'm currently using.)