On Fri, Mar 6, 2009 at 7:56 AM, ski <nor...@khine.net> wrote: > 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'
I would add another group to the beginning of the re that matches everything before the first (, e.g. r'([^(]+)\(([A-Z]+)\)( No. (\d+))?' Kent _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor