aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman2004-05-22 22:05:57 +0000
committerRichard M. Stallman2004-05-22 22:05:57 +0000
commit473f8eb3c9eccdd0eb47bf41a345fbe6de4a65d9 (patch)
tree2c18096223672d67f9657a1bb4eba7007fe2572c
parentd67029478a1418211459bda6e5cba9981665dfbf (diff)
downloademacs-473f8eb3c9eccdd0eb47bf41a345fbe6de4a65d9.tar.gz
emacs-473f8eb3c9eccdd0eb47bf41a345fbe6de4a65d9.zip
(Regexp Special): Nested repetition can be infloop.
-rw-r--r--lispref/searching.texi16
1 files changed, 9 insertions, 7 deletions
diff --git a/lispref/searching.texi b/lispref/searching.texi
index 9e26363a43a..d18587ccecb 100644
--- a/lispref/searching.texi
+++ b/lispref/searching.texi
@@ -244,13 +244,15 @@ first tries to match all three @samp{a}s; but the rest of the pattern is
244The next alternative is for @samp{a*} to match only two @samp{a}s. With 244The next alternative is for @samp{a*} to match only two @samp{a}s. With
245this choice, the rest of the regexp matches successfully.@refill 245this choice, the rest of the regexp matches successfully.@refill
246 246
247Nested repetition operators can be extremely slow if they specify 247Nested repetition operators can be extremely slow or loop infinitely
248backtracking loops. For example, it could take hours for the regular 248if they use repetition operators inside repetition operators. For
249expression @samp{\(x+y*\)*a} to try to match the sequence 249example, it could take hours for the regular expression
250@samp{xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxz}, before it ultimately fails. 250@samp{\(x+y*\)*a} to try to match the sequence
251The slowness is because Emacs must try each imaginable way of grouping 251@samp{xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxz}, before it ultimately
252the 35 @samp{x}s before concluding that none of them can work. To make 252fails. Emacs must try each way of grouping the 35 @samp{x}s before
253sure your regular expressions run fast, check nested repetitions 253concluding that none of them can work. Even worse, @samp{\(x*\)*} can
254match the null string in infinitely many ways, so it causes an
255infinite loop. To avoid these problems, check nested repetitions
254carefully. 256carefully.
255 257
256@item @samp{+} 258@item @samp{+}