[issue19055] Regular expressions: * does not match as many repetitions as possible.

Matthew Barnett report at bugs.python.org
Fri Sep 20 02:00:51 CEST 2013


Matthew Barnett added the comment:

The behaviour is correct.

Here's a summary of what's happening:-


First iteration of the repeated group:

    Try the first branch. Can match "a".

Second iteration of the repeated group:

    Try the first branch. Can't match "a".
    Try the second branch. Can't match "ab".

Continue with the remainder of the pattern.

Can't match "c", therefore backtrack to the first iteration of the repeated group:

    Try the second branch. Can match "ab".

Second iteration of the repeated group:

    Try the first branch. Can match "a".

Third iteration of the repeated group:

    Try the first branch. Can't match "a".
    Try the second branch. Can't match "ab".

Continue with the remainder of the pattern.

Can match "c".

Reached the end of the pattern. It has matched "abac".

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue19055>
_______________________________________


More information about the Python-bugs-list mailing list