Re: regex plea for help

Discussion in 'Python' started by Bob Gailer, Jun 27, 2003.

  1. Bob Gailer

    Bob Gailer Guest

    At 03:29 PM 6/27/2003 -0400, 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

    303 442 2625


    ---
    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
    Bob Gailer, Jun 27, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    10
    Views:
    544
    Otis Mukinfus
    Apr 15, 2006
  2. Mason A. Clark

    A plea: where are the links?

    Mason A. Clark, Sep 4, 2005, in forum: HTML
    Replies:
    3
    Views:
    364
    Jim Moe
    Sep 4, 2005
  3. regex plea for help

    , Jun 27, 2003, in forum: Python
    Replies:
    0
    Views:
    640
  4. Martin Bless
    Replies:
    54
    Views:
    1,057
    David MacQuigg
    Mar 6, 2004
  5. Richard Heathfield
    Replies:
    30
    Views:
    664
Loading...

Share This Page