Looking for a regular expression for this...
Anthra Norell
anthra.norell at tiscalinet.ch
Sun Jul 30 04:26:55 EDT 2006
----- Original Message -----
From: <malahal at us.ibm.com>
To: <python-list at python.org>
Sent: Friday, July 28, 2006 10:30 PM
Subject: Looking for a regular expression for this...
> 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.
> The answer should be "Y" for host hostname3 and "X" for either host
> hostname1 or hostname2.
>
> Thanks in advance.
>
> --Malahal.
> --
> http://mail.python.org/mailman/listinfo/python-list
Malahal, may I make this suggestion:
##############
>>> import SE # Cheese Shop
>>> Names_Filter = SE.SE (' <EAT> "~filename .*~=(10)=: " "~host .*~==, " ')
>>> print Names_Filter (s)
filename X: host hostname1, host hostname2,
filename Y: host hostname3,
Or: Without redundant words:
>>> Names_Filter = SE.SE (' <EAT> "~filename .*~=(10)=: " "~host .*~==, " | "filename =" "host =" ", (10)=(10)" "~, $~=(10)" ')
>>> print Names_Filter (s)
X: hostname1, hostname2
Y: hostname3
##############
Regards
Frederic
More information about the Python-list
mailing list