[Tutor] using re groups
ski
norman at khine.net
Fri Mar 6 13:56:03 CET 2009
Hello,
I have this:
>>> import re
>>> s = "Association of British Travel Agents (ABTA) No. 56542\nAir
Travel Organisation Licence (ATOL)\nAppointed Agents of IATA
(IATA)\nIncentive Travel & Meet. Association (ITMA)"
>>> licenses = re.split("\n+", s)
>>> licenseRe = re.compile(r'\(([A-Z]+)\)( No. (\d+))?')
>>> for license in licenses:
... m = licenseRe.search(license)
... print m.group(1, 3)
...
('ABTA', '56542')
('ATOL', None)
('IATA', None)
('ITMA', None)
What is the best way to also extract the affiliation name i.e:
'Association of British Travel Agents',
'Air Travel Organisation Licence'
etc..
Thanks
Norman
More information about the Tutor
mailing list