Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python regex strange behavior [duplicate]

Tags:

python

regex

I've discovered something that I can't explain in Python re module. Compilation of (a*)* or (a*|b)* throws an error:

raise error, v # invalid expression sre_constants.error: nothing to repeat

I've tested this regexp in javascript and it seems to be ok.

Is it a bug?

like image 531
f0b0s Avatar asked May 03 '11 12:05

f0b0s


2 Answers

Yes, it's a bug (or at least a misfeature). It's complaining that if a* matches nothing, it doesn't know how to capture 0 or more "nothings".

like image 173
Mu Mind Avatar answered Oct 07 '22 13:10

Mu Mind


A bug in Python.

http://bugs.python.org/issue2537

http://bugs.python.org/issue214033

Maybe a "bug" is not the correct word here. Different kind of interpretation...

like image 29
lzap Avatar answered Oct 07 '22 13:10

lzap