I'm learning regex. When I match this:
I get 3 matches: 0-0, 1-2, 3 5, and 5:2.
When I try adding a question mark at the end of the regex (
\d[^\w]\d?), my matches don't change.
When I move the question mark to after the square bracket (
\d[^\w]?\d), the matches are now 30, 01, 20, 03, 15, and 20.
When I move the question mark to before the square bracket (
\d?[^\w]\d), my matches are the same as in the first case.
Why is this? I know the
? operator marks the preceding character as optional, so I expected the behaviour in the second case, but not in the first or third.