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

Reedick, Andrew jr9445 at ATT.COM
Wed Feb 13 19:48:54 CET 2008


> -----Original Message-----
> From: python-list-bounces+jr9445=att.com at python.org [mailto:python-
> list-bounces+jr9445=att.com at python.org] On Behalf Of mensanator at aol.com
> Sent: Wednesday, February 13, 2008 1:41 PM
> To: python-list at python.org
> Subject: Re: Regular Expression for Prime Numbers (or How I came to
> fail at them, and love the bomb)
> 
> On Feb 13, 9:48 am, Carsten Haese <cars... at uniqsys.com> wrote:
> > On Wed, 2008-02-13 at 07:31 -0800, cokofree... 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".
> 
> But why doesn't it work when you make that change?


It does work.  Read the referenced website.

If there is a match then 
	the number isn't prime
else # no match
	the number is prime.



*****

The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers. GA622





More information about the Python-list mailing list