diff --git a/Doc/howto/regex.rst b/Doc/howto/regex.rst index 7486a378dbb06f..10952eb8e7f67c 100644 --- a/Doc/howto/regex.rst +++ b/Doc/howto/regex.rst @@ -7,7 +7,6 @@ :Author: A.M. Kuchling .. TODO: - Document lookbehind assertions Better way of displaying a RE, a string, and what it matches Mention optional argument to match.groups() Unicode (at least a reference) @@ -1061,6 +1060,73 @@ end in either ``bat`` or ``exe``: ``.*[.](?!bat$|exe$)[^.]*$`` +Lookbehind Assertions +--------------------- + +Lookbehind assertions work similarly to lookahead assertions, but they look +backwards in the string instead of forwards. They are available in both +positive and negative form, and look like this: + +``(?<=...)`` + Positive lookbehind assertion. This succeeds if the contained regular + expression, represented here by ``...``, successfully matches ending at the + current location, and fails otherwise. The matching engine doesn't advance; + the rest of the pattern is tried right where the assertion started. + +``(?