Positions of regexp groups

Discussion in 'Python' started by Magnus Lie Hetland, Apr 8, 2005.

  1. Just a quick question: Does anyone have a simple way of finding the
    positions (start, end) of the groups in a regexp match? AFAICS, the re
    API can only return the contents...?

    --
    Magnus Lie Hetland Fall seven times, stand up eight
    http://hetland.org [Japanese proverb]
    Magnus Lie Hetland, Apr 8, 2005
    #1
    1. Advertising

  2. Magnus Lie Hetland

    John Machin Guest

    On Fri, 8 Apr 2005 13:18:27 +0000 (UTC), (Magnus
    Lie Hetland) wrote:

    >Just a quick question: Does anyone have a simple way of finding the
    >positions (start, end) of the groups in a regexp match? AFAICS, the re
    >API can only return the contents...?


    These documented methods of the match object aren't simple enough???
    """
    start( [group])
    end( [group])

    Return the indices of the start and end of the substring matched by
    group
    """


    and there's span() which returns a tuple (start, end) ... what simpler
    could you ask for, Mr Occam?
    John Machin, Apr 8, 2005
    #2
    1. Advertising

  3. Magnus Lie Hetland

    Tim Peters Guest

    [Magnus Lie Hetland]
    > Just a quick question: Does anyone have a simple way of finding the
    > positions (start, end) of the groups in a regexp match? AFAICS, the re
    > API can only return the contents...?


    Read the docs for match objects, esp. the start(), end(), and span() methods.
    Tim Peters, Apr 8, 2005
    #3
  4. In article <>, Tim
    Peters wrote:
    >[Magnus Lie Hetland]
    >> Just a quick question: Does anyone have a simple way of finding the
    >> positions (start, end) of the groups in a regexp match? AFAICS, the re
    >> API can only return the contents...?

    >
    >Read the docs for match objects, esp. the start(), end(), and span()
    >methods.


    Right. I was just now editing the regex-stuff in my book for the
    second edition, and found that I had, in fact, written about just this
    behaviour. <blush/>

    Oh, well. I guess it's a feature I don't use much :}

    Thanks, anyway.

    --
    Magnus Lie Hetland Fall seven times, stand up eight
    http://hetland.org [Japanese proverb]
    Magnus Lie Hetland, Apr 10, 2005
    #4
    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. Petra Hübner
    Replies:
    0
    Views:
    430
    Petra Hübner
    Feb 16, 2004
  2. anonymous
    Replies:
    1
    Views:
    4,564
    Francisco Padron
    May 8, 2005
  3. Knut Krueger
    Replies:
    2
    Views:
    435
    Knut Krueger
    May 21, 2007
  4. Joao Silva
    Replies:
    16
    Views:
    344
    7stud --
    Aug 21, 2009
  5. Jason S
    Replies:
    1
    Views:
    94
Loading...

Share This Page