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

Rafael Sachetto rsachetto at gmail.com
Wed Feb 13 17:32:49 CET 2008


with this works:

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

but it match the non-prime numbers. So re_prime(2) will return null
and  re_prime(4) will return a match

2008/2/13, Carsten Haese <carsten at uniqsys.com>:
> 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
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


--
Rafael Sachetto Oliveira

Sir - Simple Image Resizer
http://rsachetto.googlepages.com



More information about the Python-list mailing list