Regular Expression for Prime Numbers (or How I came to fail at them, and love the bomb)

Carsten Haese carsten at uniqsys.com
Wed Feb 13 10:48:46 EST 2008


On Wed, 2008-02-13 at 07:31 -0800, cokofreedom at gmail.com wrote:
>     return re.match("^1?$|^(11+?)\1+$", convert)

That needs to be either

return re.match(r"^1?$|^(11+?)\1+$", convert)

or

return re.match("^1?$|^(11+?)\\1+$", convert)

in order to prevent "\1" from being read as "\x01".

-- 
Carsten Haese
http://informixdb.sourceforge.net





More information about the Python-list mailing list