regexp matching end of line or comma
- From: Jean-Michel Pichavant <jeanmichel@xxxxxxxxxxx>
- Date: Thu, 25 Nov 2010 15:40:49 +0100
Hy guys,
I'm struggling matching patterns ending with a comma ',' or an end of line '$'.
import re
ex1 = 'sumthin,'
ex2 = 'sumthin'
m1 = re.match('(?P<something>\S+),', ex1)
m2 = re.match('(?P<something>\S+)$', ex2)
m3 = re.match('(?P<something>\S+)[,$]', ex1)
m4 = re.match('(?P<something>\S+)[,$]', ex2)
print m1, m2
print m3
print m4
<_sre.SRE_Match object at 0x8834de0> <_sre.SRE_Match object at 0x8834e20>
<_sre.SRE_Match object at 0x8834e60>
None
My problem is that m4 is None while I'd like it to match ex2.
Any clue ?
JM
.
- Follow-Ups:
- Re: regexp matching end of line or comma
- From: Saul Spatz
- Re: regexp matching end of line or comma
- Prev by Date: Re: a regexp riddle: re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and c') =? ('a', 'bbb', 'c')
- Next by Date: Re: what a cheap rule
- Previous by thread: do something every n seconds
- Next by thread: Re: regexp matching end of line or comma
- Index(es):
Relevant Pages
|