Re.findall() & Re.finditer()

  • Asked to answer
    + 3 comments
    Endorsed by cannibal

    (?=...)

    Matches if ... matches next, but doesn’t consume any of the string. This is called a lookahead assertion. For example, Isaac (?=Asimov) will match 'Isaac ' only if it’s followed by 'Asimov'.
    

    (?<=...)

    Matches if the current position in the string is preceded by a match for ... that ends at the current position. This is called a positive lookbehind assertion. (?<=abc)def will find a match in abcdef, since the lookbehind will back up 3 characters and check if the contained pattern matches.
    

    source: https://docs.python.org/2/library/re.html