> You have two capturing subexpressions; 'b' is in the second one.
Did you mean (a|b) instead?
Yea, I have two capturing brackets, but the pattern is separated by |
into two parts - (a) and (b).
Afaik when (a) fails to match, the regex engine should completely
ignore the rest of the current part and move on to (b) and try to
match it against the text. And if (b) matched, the letter 'b' should
be placed inside \1.
The problem here is that \1 gets a null value while 'b' is pushed to
\2, and I don't understand why it acts this way. On mIRC, that
includes an implementation of PCRE, the letter 'b' is placed in \1 (as
I expect), though on PHP it's moved to \2.
I am aware there are other ways of doing this simple match, like
"(a|b)" or "([ab])", but this problem occured to me with a more
complicated pattern and I think "(a)|(b)" is the simplest form of
presenting it.