[Baypiggies] Bug in re module?

Glen Jarvis glen at glenjarvis.com
Thu Nov 29 20:08:00 CET 2012


import re

line = "Test2.1"

matchobj = re.match("Test2.1", line, 0)

print matchobj


yields <_sre.SRE_Match object at 0x1041bc100>


I think Jake's advice is what you're looking for.. searching instead of
matching. Or, if you really wanted to match, make it match the string and
use groups so you can have stuff before (and possibly after).


G


On Thu, Nov 29, 2012 at 10:59 AM, Glen Jarvis <glen at glenjarvis.com> wrote:

> What about the new line character in your code? Is that significant. I ask
> instead of state since I am not certain -- but it's the first thing this
> fresh pair if eyes danced to.
>
> Cheers,
>
>
> Glen
>
> On Nov 29, 2012, at 10:57 AM, Mitch Patenaude <patenaude at gmail.com> wrote:
>
> > Maybe I'm misunderstanding, but I think I have a bug in the re module:
> > mpatenaude-mbp:tmp mpatenaude$ python2.7
> > Python 2.7.3 (default, Apr 13 2012, 00:05:08)
> > [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
> > Type "help", "copyright", "credits" or "license" for more information.
> > >>> import re
> > >>> line="\tTest2.1\n"
> > >>> matchobj = re.match('Test2.1',line,0)
> > >>> matchobj
> >
> > It's not matching a very simple string.
> >
> > (I know that '.' is a special character, but it should match any
> character, including a period itself, so I didn't bother to escape it.)
> >
> > It *works* if I use findall rather than match, but I don't understand
> why.
> >
> >   -- Mitch
> > _______________________________________________
> > Baypiggies mailing list
> > Baypiggies at python.org
> > To change your subscription options or unsubscribe:
> > http://mail.python.org/mailman/listinfo/baypiggies
>



-- 

"Pursue, keep up with, circle round and round your life as a dog does his
master's chase. Do what you love. Know your own bone; gnaw at it, bury it,
unearth it, and gnaw it still."

--Henry David Thoreau
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/baypiggies/attachments/20121129/f0ca03e2/attachment.html>


More information about the Baypiggies mailing list