in reply to Re: why such an error happened?
in thread why such an error happened?

You only have one set of capturing parentheses on each side of the alternation, so you're only ever going to get one match. ie. $2 will always be undefined.
Not true.

What is true that you get only one defined capture (if there's a match), but that one can very well be $2.