Regular Expressions

Cameron Laird claird at lairds.com
Sun Mar 28 00:04:07 EST 2004


In article <76adncn7cvNZl_vdRVn-jA at centurytel.net>,
Ed Suominen  <ed-no at spam-eepatents.com> wrote:
>Sorry, the RE should be '(\d+)\s+\"([\w\']+)[,\s]+([\w\']+)'
>
>Ed Suominen wrote:
>
>> m = sre.search('(\d+)\s+\"[\w\'][,\s]+([\w\'])', s)
>> x = (int(m.group(1)), group(2), group(3))
			.
			.
			.
And the bound list should be ... well, how 'bout I just
start from the top?
  import sre

  s = '''740446505        "O'HANLON, Benjamin"'''
  m = sre.search('''(\d+)\s+"([\w']+)[,\s]+([\w']+)''', s)
  x = (int(m.group(1)), m.group(2), m.group(3))
  print x
I see we're appropriately ignoring multiple commas, missing
close quotes, ...
-- 

Cameron Laird <claird at phaseit.net>
Business:  http://www.Phaseit.net



More information about the Python-list mailing list