LibRef 4.2.1 Regular Expression Syntax
{m,n} "...you can't omit m...."
Actually, you can: for sre, it defaults to 0
>>> a4=re.compile('a{,4}')
>>> a4.match('').group(0)
''
>>> a4.match('aaaaa').group(0)
'aaaa'
This is predictable from sre_parse.py code
elif this == "{":
min, max = 0, MAXREPEAT
/* lo set to digits between { and ,.*/
if lo:
min = atoi(lo)
Result for pre seems buggy: compiles but does not
match. (so 'can't' is sort of correct, but not in way
expected -- by raising exception):
>>> import pre
>>> pa4=pre.compile('a{,4}')
>>> pa4.match('') # None response
>>> pa4.match('aaaaa').group(0)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: 'NoneType' object has no
attribute 'group'
So, suggested replacement:
"For sre, m defaults to 0; for older pre, missing m
compiles but does not match."
|