Is it bug or feature in sre?
rnd at onego.ru
Mon Jan 5 13:19:24 CET 2004
On Mon, 5 Jan 2004, Skip Montanaro wrote:
> >>> 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
- I want it to be optional, so this is not what I wanted
- this is right thing
> 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>
And I fully agree with it.
> 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?
More information about the Python-list