Looking for a regular expression for this...
faulkner
faulkner612 at comcast.net
Fri Jul 28 18:13:32 EDT 2006
idk, most regexes look surprisingly like undergrowth.
malahal, why don't you parse s into a dict? read each couple of lines
into a key-value pair.
John Machin wrote:
> malahal at us.ibm.com wrote:
> > Hi,
> > My string is a multi line string that contains "filename
> > <filename>\n" and "host <host>\n" entries among other things.
> >
> > For example: s = """ filename X
> > host hostname1
> > blah...
> > host hostname2
> > blah...
> > filename Y
> > host hostname3
> > """
> > Given a host name, I would like to get its filename (The closest
> > filename reading backwards from the host line). I could read each line
> > until I hit the host name, but I am looking for an RE that will do job.
>
> Looking for? REs don't lurk in the undergrowth waiting to be found. You
> will need to write one (unless some misguided person spoon-feeds you).
> What have you tried so far?
>
> > The answer should be "Y" for host hostname3 and "X" for either host
> > hostname1 or hostname2.
> >
> > Thanks in advance.
> >
> > --Malahal.
More information about the Python-list
mailing list