regex plea for help
Bob Gailer
bgailer at alum.rpi.edu
Fri Jun 27 15:44:52 EDT 2003
More information about the Python-list mailing list
Fri Jun 27 15:44:52 EDT 2003
- Previous message (by thread): regex plea for help
- Next message (by thread): [Python-Dev] bsddb185 module changes checked in
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
At 03:29 PM 6/27/2003 -0400, jwsacksteder at ramprecision.com wrote: >I'm trying to process through an apache log file and bust up the individual >sections into a list for further processing. There is a regex I got from a >php example that matches an entire line, but obviously, that only returns a >single element list. re.split() doesn't see to be the tool to use. I think I >need to define 'symbolic groups' in the regex to return them as distinct >elements. If someone could provide information or relevent links I would be >most appreciative. Any part of a regular expression in parentheses is treated as a group. >>> import re >>> re.findall(r'(a)b(c)', 'abcabc') [('a', 'c'), ('a', 'c')] >>>m=re.search(r'(a)b(c)', 'abcabc') >>> m.groups() ('a', 'c') You can name the groups: >>> m=re.search(r'(?P<one>a)b(?P<two>c)', 'abcabc') >>> m.groupdict() {'two': 'c', 'one': 'a'} HTH Bob Gailer bgailer at alum.rpi.edu 303 442 2625 -------------- next part -------------- --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.492 / Virus Database: 291 - Release Date: 6/24/2003
- Previous message (by thread): regex plea for help
- Next message (by thread): [Python-Dev] bsddb185 module changes checked in
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list