re module: Nothing to repeat, but no sre_constants.error: nothing to repeat ?
Vlastimil Brom
vlastimil.brom at gmail.com
Tue Feb 14 10:05:51 EST 2012
2012/2/14 Devin Jeanpierre <jeanpierreda at gmail.com>:
> Hey Pythonistas,
>
> Consider the regular expression "$*". Compilation fails with the
> exception, "sre_constants.error: nothing to repeat".
>
> Consider the regular expression "(?=$)*". As far as I know it is
> equivalent. It does not fail to compile.
>
> Why the inconsistency? What's going on here?
>
> -- Devin
> --
> http://mail.python.org/mailman/listinfo/python-list
Hi,
I don't know the reason for the observed differences either (I can
think of some optimisation issues etc.), but just wanted to mention
some other similar patterns to your lookahaed:
It seems, that groups (capturing or not capturing) also work ok:
>>> re.findall("($)*", "abc")
['', '', '', '']
>>> re.findall("(?:$)*", "abc")
['', '', '', '']
However, is there any realistic usecase for repeated zero-width anchors?
regards,
vbr
More information about the Python-list
mailing list