[Tutor] Regex puzzlement
Alan Gauld
alan.gauld at blueyonder.co.uk
Mon Aug 9 00:27:44 CEST 2004
Doh! Its always obvious once you see it!
Thanks Bill, I knew it had to be something abouyt one of the
characters but short of escaping each one in turn... I knew
about the range thing, just didn't see it.
Thanks again.
Alan G.
----- Original Message -----
From: "Bill Mill" <bill.mill at gmail.com>
To: "Alan Gauld" <alan.gauld at blueyonder.co.uk>
Cc: <tutor at python.org>
Sent: Sunday, August 08, 2004 8:03 PM
Subject: Re: [Tutor] Regex puzzlement
> Hey, that last message didn't make sense. What I meant was that it
was
> interpreted as a character range from ')' to ';', where:
>
> In [36]: ord(')')
> Out[36]: 41
>
> In [32]: ord(';')
> Out[32]: 59
>
> In [33]: ord('1')
> Out[33]: 49
>
> In [34]: ord('a')
> Out[34]: 97
>
> so anything with an ord between 41 and 59 matches your regex.
>
> Peace
> Bill Mill
>
> On Sun, 8 Aug 2004 14:57:57 -0400, Bill Mill <bill.mill at gmail.com>
wrote:
> > from the re documentation
> > (http://www.python.org/doc/current/lib/re-syntax.html):
> > If you want to include a "]" or a "-" inside a set, precede it
> > with a backslash
> >
> > What happened is that the '-' was interpreted by the regex module
as
> > meaning that you had presented a character range from '\\' to ';'.
> >
> > In [31]: ord('\\')
> > Out[31]: 92
> >
> > In [32]: ord(';')
> > Out[32]: 59
> >
> > In [33]: ord('1')
> > Out[33]: 49
> >
> > In [34]: ord('a')
> > Out[34]: 97
> >
> > Thus, anything with an ord between 92 and 59 would be interpreted
as
> > matching your regex.
> >
> > Peace
> > Bill Mill
> >
> >
> >
> > On Sun, 8 Aug 2004 19:10:43 +0100, Alan Gauld
> > <alan.gauld at blueyonder.co.uk> wrote:
> > > My turn to be confused by a regex...
> > >
> > > >>> import re
> > > >>> r = re.compile('[&()-;:,.?!]')
> > > >>> r.findall('Here is one, or two. but not 6 or 7')
> > > [',', '.', '6', '7']
> > > >>>
> > >
> > > Why is it finding the numbers?
> > > Presumably some weird regex convention amongst the chars I've
> > > put in the group, but what? And how do I get rid of it?
> > >
> > > Alan G.
> > >
> > > _______________________________________________
> > > Tutor maillist - Tutor at python.org
> > > http://mail.python.org/mailman/listinfo/tutor
> > >
> >
>
>
>
More information about the Tutor
mailing list