[Python-checkins] CVS: python/dist/src/Doc/lib libre.tex,1.75,1.76

Skip Montanaro montanaro@users.sourceforge.net
Mon, 04 Mar 2002 15:08:30 -0800


Update of /cvsroot/python/python/dist/src/Doc/lib
In directory usw-pr-cvs1:/tmp/cvs-serv30742

Modified Files:
	libre.tex 
Log Message:
add simple example of avoiding backtracking


Index: libre.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/lib/libre.tex,v
retrieving revision 1.75
retrieving revision 1.76
diff -C2 -d -r1.75 -r1.76
*** libre.tex	25 Feb 2002 18:56:45 -0000	1.75
--- libre.tex	4 Mar 2002 23:08:28 -0000	1.76
***************
*** 803,810 ****
  \subsection{Examples}
  
- %\begin{list}{}{\leftmargin 0.7in \labelwidth 0.65in}
- 
- %\item[Simulating scanf]
- 
  \leftline{\strong{Simulating \cfunction{scanf()}}}
  
--- 803,806 ----
***************
*** 852,857 ****
  
  \begin{verbatim}
!     ([^\s]+) - (\d+) errors, (\d+) warnings
  \end{verbatim}
  
! %\end{list}
--- 848,873 ----
  
  \begin{verbatim}
!     (\S+) - (\d+) errors, (\d+) warnings
  \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 ?
!       File "/usr/local/lib/python2.3/sre.py", line 132, in match
! 	return _compile(pattern, flags).match(string)
!     RuntimeError: maximum recursion limit exceeded
! \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.