alex23 [EMAIL PROTECTED] wrote:
Tim Roberts wrote:
What is your signature supposed to be? It looks like you are trying to
inject ANSI terminal escape sequences. The vast majority of Usenet
participants are now reading these articles through GUI newsreaders or
web-based readers which show
※ [EMAIL PROTECTED] (Peter Otten)》之銘言:
到底在累什麼啊? wrote:
Thanks a lot! I have never thought of that.
But what if there's not only commas, but also periods and semicolons? I
want to find words between 2 near by punctuations. I think it would make
it difficult to use split instead of regular
[EMAIL PROTECTED] (¨ì©³¦b²Ö¤°»ò°Ú¡H) wrote:
¡° [EMAIL PROTECTED] (Peter Otten)¡n¤§»Ê¨¥¡G
¨ì©³¦b²Ö¤°»ò°Ú¡H wrote:
Thanks a lot! I have never thought of that.
But what if there's not only commas, but also periods and semicolons? I
want to find words between 2 near by punctuations. I think it
Tim Roberts wrote:
What is your signature supposed to be? It looks like you are trying to
inject ANSI terminal escape sequences. The vast majority of Usenet
participants are now reading these articles through GUI newsreaders or
web-based readers which show this as 5 lines of unrecognizable
Tim Roberts wrote:
What is your signature supposed to be? It looks like you are trying to
inject ANSI terminal escape sequences. The vast majority of Usenet
participants are now reading these articles through GUI newsreaders or
web-based readers which show this as 5 lines of unrecognizable
※ [EMAIL PROTECTED] (Thomas Nelson)》之銘言:
How about
my_string = We the people of the United States, in order to form a
more perfect union, establish justice, insure domestic
tranquility,..
print (x for x in my_string.split(,) if justice in x).next()
This isn't a regular expression, but it
But what if there's not only commas, but also periods and semicolons? I
want to find words between 2 near by punctuations. I think it would make
it difficult to use split instead of regular expression.
You could use re.split(r\W, text) instead of the string split method
to split on all
¨ì©³¦b²Ö¤°»ò°Ú¡H wrote:
How about
my_string = We the people of the United States, in order to form a
more perfect union, establish justice, insure domestic
tranquility,..
print (x for x in my_string.split(,) if justice in x).next()
This isn't a regular expression, but it gives what
I want words between 2 nearby commas with a specific word in them.
For example,in the text blow:
We the people of the United States, in order to form a more perfect union,
establish justice, insure domestic tranquility,..
I want justice and the words between the 2 nearest commas, which is
¨ì©³¦b²Ö¤°»ò°Ú¡H wrote:
I want justice and the words between the 2 nearest commas, which is
establish justice
All I can come up with is
r,(.*?justice.*?),
but the result is
in order to form a more perfect union, establish justice
Apreciate any help.
,([^,]*justice[^,]*),
How about
my_string = We the people of the United States, in order to form a
more perfect union, establish justice, insure domestic
tranquility,..
print (x for x in my_string.split(,) if justice in x).next()
This isn't a regular expression, but it gives what you're looking for.
THN
--
- Original Message -
From: [EMAIL PROTECTED]
To: python-list@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
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...
[EMAIL PROTECTED] 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
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
filename\n and host host\n
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:
[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:
17 matches
Mail list logo