http://qs321.pair.com?node_id=372788


in reply to Greedy regexp matching: differences between man page and implementation?

Both, the documentation and the implementation are correct, because any regex match favours the leftmost interpretation. If you reorder your alternatives in your capturing first parentheses, I expect you will see the other match ab c, but as the single-letter a is already enough to make the first parentheses match once, the alternation won't be tried at all, as the overall match can succeed that way.

With Perls regular expression engine, you will always get the longest leftmost match, with "leftmost" taking precedence over "longest", which is what is biting you in the first capture.