Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
a8e1d81b
Kaydet (Commit)
a8e1d81b
authored
Mar 04, 2002
tarafından
Skip Montanaro
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
add simple example of avoiding backtracking
üst
dd989e1c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
6 deletions
+22
-6
libre.tex
Doc/lib/libre.tex
+22
-6
No files found.
Doc/lib/libre.tex
Dosyayı görüntüle @
a8e1d81b
...
...
@@ -802,10 +802,6 @@ The string passed to \function{match()} or \function{search()}.
\subsection
{
Examples
}
%\begin{list}{}{\leftmargin 0.7in \labelwidth 0.65in}
%\item[Simulating scanf]
\leftline
{
\strong
{
Simulating
\cfunction
{
scanf()
}}}
Python does not currently have an equivalent to
\cfunction
{
scanf()
}
.
...
...
@@ -851,7 +847,27 @@ you would use a \cfunction{scanf()} format like
The equivalent regular expression would be
\begin{verbatim}
([
^
\s
]+) - (
\d
+) errors, (
\d
+) warnings
(
\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}
%\end{list}
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.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment