How to find all possibly overlapping matches?

Discussion in 'Python' started by kj, Aug 12, 2009.

  1. kj

    kj Guest

    re.findall finds all non-overlapping matches, but what if one wants
    all (maximal) matches, even those that overlap?

    All the solutions I can come up involve calling re.search iteratively,
    each time giving it a pos parameter starting just after the start
    of the previous match.

    Is there a built-in solution to such a task?

    TIA!

    kynn
     
    kj, Aug 12, 2009
    #1
    1. Advertising

  2. kj

    MRAB Guest

    kj wrote:
    >
    > re.findall finds all non-overlapping matches, but what if one wants
    > all (maximal) matches, even those that overlap?
    >
    > All the solutions I can come up involve calling re.search iteratively,
    > each time giving it a pos parameter starting just after the start
    > of the previous match.
    >
    > Is there a built-in solution to such a task?
    >

    Not in the re module.

    It has been requested and is in my regex implementation at
    http://bugs.python.org/issue2636 if you want to try that.
     
    MRAB, Aug 12, 2009
    #2
    1. Advertising

  3. kj

    kj Guest

    In <> MRAB <> writes:

    >kj wrote:
    >>
    >> re.findall finds all non-overlapping matches, but what if one wants
    >> all (maximal) matches, even those that overlap?
    >>
    >> All the solutions I can come up involve calling re.search iteratively,
    >> each time giving it a pos parameter starting just after the start
    >> of the previous match.
    >>
    >> Is there a built-in solution to such a task?
    >>

    >Not in the re module.


    >It has been requested and is in my regex implementation at
    >http://bugs.python.org/issue2636 if you want to try that.


    Cool. Thanks!

    kynn
     
    kj, Aug 12, 2009
    #3
    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. Tony
    Replies:
    4
    Views:
    2,189
    Andy De Petter
    Nov 27, 2003
  2. =?ISO-8859-1?Q?Andr=E9_S=F8reng?=

    Overlapping matches in Regular Expressions

    =?ISO-8859-1?Q?Andr=E9_S=F8reng?=, Apr 12, 2005, in forum: Python
    Replies:
    1
    Views:
    435
    Fredrik Lundh
    Apr 12, 2005
  3. Mystilleef
    Replies:
    5
    Views:
    1,104
    Fredrik Lundh
    Dec 15, 2005
  4. Rehceb Rotkiv

    Overlapping matches

    Rehceb Rotkiv, Apr 1, 2007, in forum: Python
    Replies:
    3
    Views:
    312
    Rehceb Rotkiv
    Apr 2, 2007
  5. Peng Yu

    How find all overlapping pattern?

    Peng Yu, Feb 7, 2011, in forum: Perl Misc
    Replies:
    8
    Views:
    208
Loading...

Share This Page