[Python-checkins] CVS: python/dist/src/Doc/lib libre.tex,1.77,1.78
Sjoerd Mullender
sjoerd@acm.org
Sat, 16 Mar 2002 10:35:18 +0100
I don't think the first example will actually work: there is a "c" missing in
the to-be-matched string.
"Fred L. Drake" wrote:
>
> Update of /cvsroot/python/python/dist/src/Doc/lib
> In directory usw-pr-cvs1:/tmp/cvs-serv24044/lib
>
> Modified Files:
> libre.tex
> Log Message:
> Clarify the descriptions of the positive and negative lookbehind assertions.
> Added examples of positive lookbehind assertions.
> This closes SF bug #529708.
>
> Index: libre.tex
> ===================================================================
> RCS file: /cvsroot/python/python/dist/src/Doc/lib/libre.tex,v
> retrieving revision 1.77
> retrieving revision 1.78
> diff -C2 -d -r1.77 -r1.78
> *** libre.tex 5 Mar 2002 04:02:39 -0000 1.77
> --- libre.tex 16 Mar 2002 05:58:12 -0000 1.78
> ***************
> *** 273,288 ****
> \item[\code{(?<=...)}] Matches if the current position in the string
> is preceded by a match for \regexp{...} that ends at the current
> ! position. This is called a positive lookbehind assertion.
> ! \regexp{(?<=abc)def} will match \samp{abcdef}, since the lookbehind
> ! will back up 3 characters and check if the contained pattern matches.
> ! The contained pattern must only match strings of some fixed length,
> ! meaning that \regexp{abc} or \regexp{a|b} are allowed, but \regexp{a*}
> ! isn't.
>
> \item[\code{(?<!...)}] Matches if the current position in the string
> ! is not preceded by a match for \regexp{...}. This
> ! is called a negative lookbehind assertion. Similar to positive lookbehind
> assertions, the contained pattern must only match strings of some
> ! fixed length.
>
> \end{list}
> --- 273,309 ----
> \item[\code{(?<=...)}] Matches if the current position in the string
> is preceded by a match for \regexp{...} that ends at the current
> ! position. This is called a \dfn{positive lookbehind assertion}.
> ! \regexp{(?<=abc)def} will find a match in \samp{abcdef}, since the
> ! lookbehind will back up 3 characters and check if the contained
> ! pattern matches. The contained pattern must only match strings of
> ! some fixed length, meaning that \regexp{abc} or \regexp{a|b} are
> ! allowed, but \regexp{a*} and \regexp{a\{3,4\}} are not. Note that
> ! patterns which start with positive lookbehind assertions will never
> ! match at the beginning of the string being searched; you will most
> ! likely want to use the \function{search()} function rather than the
> ! \function{match()} function:
> !
> ! \begin{verbatim}
> ! >>> import re
> ! >>> m = re.search('(?<=abc)def', 'abdef')
> ! >>> m.group(0)
> ! 'def'
> ! \end{verbatim}
> !
> ! This example looks for a word following a hyphen:
> !
> ! \begin{verbatim}
> ! >>> m = re.search('(?<=-)\w+', 'spam-egg')
> ! >>> m.group(0)
> ! 'egg'
> ! \end{verbatim}
>
> \item[\code{(?<!...)}] Matches if the current position in the string
> ! is not preceded by a match for \regexp{...}. This is called a
> ! \dfn{negative lookbehind assertion}. Similar to positive lookbehind
> assertions, the contained pattern must only match strings of some
> ! fixed length. Patterns which start with negative lookbehind
> ! assertions will may match at the beginning of the string being
> ! searched.
>
> \end{list}
>
> _______________________________________________
> Python-checkins mailing list
> Python-checkins@python.org
> http://mail.python.org/mailman/listinfo/python-checkins