[Python-checkins] python/dist/src/Doc/lib libre.tex,1.97,1.98
loewis@users.sourceforge.net
loewis@users.sourceforge.net
Sat, 03 May 2003 03:57:56 -0700
Update of /cvsroot/python/python/dist/src/Doc/lib
In directory sc8-pr-cvs1:/tmp/cvs-serv23113
Modified Files:
libre.tex
Log Message:
Patch #731514: Update recursion documentation to mention simple recursion.
Index: libre.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/lib/libre.tex,v
retrieving revision 1.97
retrieving revision 1.98
diff -C2 -d -r1.97 -r1.98
*** libre.tex 20 Apr 2003 01:48:59 -0000 1.97
--- libre.tex 3 May 2003 10:57:53 -0000 1.98
***************
*** 897,909 ****
\end{verbatim}
! \leftline{\strong{Avoiding backtracking}}
! If you create regular expressions that require the engine to perform a lot
! of backtracking, you may encounter a RuntimeError exception with the message
! \code{maximum recursion limit exceeded}. For example,
\begin{verbatim}
! >>> s = "<" + "that's a very big string!"*1000 + ">"
! >>> re.match('<.*?>', s)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
--- 897,910 ----
\end{verbatim}
! \leftline{\strong{Avoiding recursion}}
! If you create regular expressions that require the engine to perform a
! lot of recursion, you may encounter a RuntimeError exception with
! the message \code{maximum recursion limit} exceeded. For example,
\begin{verbatim}
! >>> import re
! >>> s = 'Begin ' + 1000*'a very long string ' + 'end'
! >>> re.match('Begin (\w| )*? end', s).end()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
***************
*** 913,919 ****
\end{verbatim}
! You can often restructure your regular expression to avoid backtracking.
! The above regular expression can be recast as
! \regexp{\textless[\textasciicircum \textgreater]*\textgreater}. As a
! further benefit, such regular expressions will run faster than their
! backtracking equivalents.
--- 914,922 ----
\end{verbatim}
! You can often restructure your regular expression to avoid recursion.
!
! \versionadded[Simple uses of the \regexp{*?} pattern are now
! special-cased to avoid recursion. Thus, the above regular expression
! can avoid recursion by being recast as \regexp{Begin [a-zA-Z0-9_ ]*?end}.
! As a further benefit, such regular expressions will run faster than
! their recursive equivalents.]{2.3}