a string problem

micklee74 at hotmail.com micklee74 at hotmail.com
Tue Jun 13 16:05:49 CEST 2006


John Salerno wrote:

> micklee74 at hotmail.com wrote:
> > hi
> >
> > if i have a some lines  like this
> > a ) "here is first string"
> > b ) "here is string2"
> > c ) "here is string3"
> >
> > When i specify i only want to print the lines that contains "string" ie
> > the first line and not the others. If i use re module, how to compile
> > the expression to do this? I tried the re module and using simple
> > search() and everytime it gives me all the 3 lines that have "string"
> > in it, whereas i only need line 1.
> > If re module is not needed, how can i use string manipulation to do
> > this? thanks
> >
>
> As far as re goes, you can search for the pattern '\bstring\b', which
> will find just the word 'string' itself. Not sure if there's a better
> way to do it with REs.
>
> And I'm actually ashamed to admit that I know the RE way, but not the
> regular string manipulation way, if there is one! This seems like
> something easy enough to do without REs though.

just curious , if RE has the \b and it works, can we look into the
source of re and see how its done for \b ?




More information about the Python-list mailing list