python replace/sub/wildcard/regex issue
alex23
wuwei23 at gmail.com
Mon Jan 18 23:33:53 EST 2010
On Jan 19, 2:04 pm, tom <badoug... at gmail.com> wrote:
> trying to figure out how to solve what should be an easy python/regex/
> wildcard/replace issue.
> but i'm missing something...
Well, some would say you've missed the most obvious solution of _not_
using regexps :)
I'd probably do it via string methods wrapped up in a helper function:
>>> def extract(text):
... first, rest = text.split('<', 1)
... ignore, last = rest.rsplit('>', 1)
... return '%s foo %s' % (first, last)
...
>>> extract('Soo Choi</span>LONGEDITBOX">Apryl Berney')
'Soo Choi foo Apryl Berney'
>>> extract('Soo Choi</span>LONGEDITBOX">Joel Franks')
'Soo Choi foo Joel Franks'
>>> extract('Joel Franks</span>GEDITBOX">Alexander Yamato')
'Joel Franks foo Alexander Yamato'
More information about the Python-list
mailing list