which re a|l|t|e|r|n|a|t|i|v|e matched?

Skip Montanaro skip at pobox.com
Mon Oct 27 14:32:38 EST 2003


    >> is there a way to know what alternative was matched?

    >>> import re
    >>> matcher = re.compile('(A)|(B)|(C)').match
    >>> matcher('ABC').lastindex
    1
    >>> matcher('BAC').lastindex
    2
    >>> matcher('CAB').lastindex
    3

Ah, thanks.

    Tim> You can't have more than 99 capturing groups in a single regexp,
    Tim> though.

That I can worm around.

Thx,

Skip






More information about the Python-list mailing list