possible bug in re expression?

Terry Reedy tjreedy at udel.edu
Fri Apr 25 14:32:30 EDT 2014


On 4/25/2014 12:30 PM, Robin Becker wrote:
> Whilst translating some javascript code I find that this
>
> A=re.compile('.{1,+3}').findall(p)
>
> doesn't give any error, but doesn't manage to find the strings in p that
> I want len(A)==>0, the correct translation should have been
>
> A=re.compile('.{1,3}').findall(p)
>
> which works fine.
>
> should
>
> re.compile('.{1,+3}')
>
> raise an error? It doesn't on python 2.7 or 3.3.

And it should not because it is not an error. '+' means 'match 1 or more 
occurrences of the preceding re' and the preceding re is ','.

 >>> re.match('a{1,+3}', 'a{1,,,3}').group()
'a{1,,,3}'

I suppose that one could argue that '{' alone should be treated as 
special immediately, and not just when a matching '}' is found, and 
should disable other special meanings. I wonder what JS does if there is 
no matching '}'?

-- 
Terry Jan Reedy




More information about the Python-list mailing list