- Original Message -
From: <[EMAIL PROTECTED]>
To:
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
> \n" and "host \n" entries among
[EMAIL PROTECTED] wrote:
> OK, I tried this one. I am actually trying to parse dhcpd.conf file.
>
> def get_filename(self):
> p = "^[ \t]*filename[ \t]+(\S+).*?host[ \t]+%s\s*$" % self.host
> pat = re.compile(p, re.MULTILINE | re.DOTALL)
> mo = pat.search(self.confdata)
> if mo:
>
OK, I tried this one. I am actually trying to parse dhcpd.conf file.
def get_filename(self):
p = "^[ \t]*filename[ \t]+(\S+).*?host[ \t]+%s\s*$" % self.host
pat = re.compile(p, re.MULTILINE | re.DOTALL)
mo = pat.search(self.confdata)
if mo:
return mo.group(1)
else:
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:
> [EMAIL PROTECTED] wrote:
> > Hi,
> > My string is a multi line string that contains "filename
> > \n" and "host \n" entr
[EMAIL PROTECTED] wrote:
> Hi,
> My string is a multi line string that contains "filename
> \n" and "host \n" entries among other things.
>
> For example: s = """ filename X
> host hostname1
> blah...
> host hostname2
>
Hi,
My string is a multi line string that contains "filename
\n" and "host \n" entries among other things.
For example: s = """ filename X
host hostname1
blah...
host hostname2
blah...
f