re.match question

Thomas Svensson thomas.svensson at era.ericsson.se
Thu Oct 5 12:16:25 EDT 2000


Tony Sideris wrote:
> 
> "Thomas Svensson" <thomas.svensson at era.ericsson.se> wrote in message
> news:39DC9F7C.67B71D52 at era.ericsson.se...
> > Hello,
> >
> > I'm matching a list of strings. I want "xxxBar" to be a match but not
> > "xxxFooBar", xxx can be anything. I've tried the following:
> >
> > re.match('^.*?(?!Foo)Bar$', word)
> >
> > re.match('^.*?(Foo){0}Bar$', word)
> >
> > But they all returns a match. What am I doing wrong?? I think this
> > should be an easy thing to do.
> >
> >
> > Thanks for any help,
> > Thomas
> 
> re.match(r'^[^(?:Foo)]*Bar', 'xxxFooBar');
> 
> seems to be working for me. the above line fails, 'xxxBar' passes. may need
> further tweeking...
> -Tony

Thanks,

But this seems not to be quite correct. If I try "xxxoBar" it also
fails, that should only happen for the complete substring ("Foo").

/ Thomas



More information about the Python-list mailing list