Problems with regexps
Kirk Strauser
kirk at daycos.com
Fri Nov 7 18:00:34 EST 2003
OK, let me give a clearer demonstration. Given this program:
#!/usr/bin/env python
import re
sample = 'FOO= BAR'
if re.search(r'[^=]\s+BAR', sample):
print 'Match 1.'
if re.search(r'[^=]\s*BAR', sample):
print 'Match 2.'
When run, it produces "Match 2.". Why? I want to match:
1) Anything but '=', followed by
2) Zero or more spaces, followed by
3) 'BAR'
The first pattern correct does *not* match. Why doesn't the '= ' get struck
down by the '[^=]' pattern before a '\s+' but not before '\s*'?
Thanks,
--
Kirk Strauser
The Day Companies
More information about the Python-list
mailing list