Python 2.3.1 (#1, Sep 25 2003, 10:15:04)
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2
......
>>> re.compile("(?P<gr>[A-Z]*)?")
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/local/lib/python2.3/sre.py", line 179, in compile
return _compile(pattern, flags)
File "/usr/local/lib/python2.3/sre.py", line 229, in _compile
raise error, v # invalid expression
sre_constants.error: nothing to repeat
I wonder why I can't do this? I guess it's of terrible style, but
is this behaviour intentional or not?
Probably it is good idea to mention this in Python update path
documents. Otherwise some old programs will mysteriously fail.
Sincerely yours, Roman A.Suzi
--
- Petrozavodsk - Karelia - Russia - mailto:r...@onego.ru -
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
>
> >>> 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]*)"
- I want it to be optional, so this is not what I wanted
> or
>
> "(?P<gr>[A-Z]+)?"
- 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?
Python 1.5.2
re
> Skip