Is it bug or feature in sre?
Skip Montanaro
skip at pobox.com
Mon Jan 5 07:07:13 EST 2004
>>> re.compile("(?P<gr>[A-Z]*)?")
Roman> Traceback (most recent call last):
...
Roman> sre_constants.error: nothing to repeat
Roman> I wonder why I can't do this?
Is there some reason why
"(?P<gr>[A-Z]*)"
or
"(?P<gr>[A-Z]+)?"
isn't sufficient? You specified the zero-or-more repetition inside the
group. There's nothing else to have zero-or-one of.
Roman> I guess it's of terrible style, but is this behaviour intentional
Roman> or not?
I suspect it's intentional, since Fredrik went to the trouble of raising an
exception with a useful error message. <wink>
Roman> Probably it is good idea to mention this in Python update path
Roman> documents. Otherwise some old programs will mysteriously fail.
What were you converting from, an older version of sre, pre, regex, or
(shudder) regexp?
Skip
More information about the Python-list
mailing list