From: Richard M. Stallman Date: Sat, 22 May 2004 22:05:57 +0000 (+0000) Subject: (Regexp Special): Nested repetition can be infloop. X-Git-Tag: ttn-vms-21-2-B4~6098 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=473f8eb3c9eccdd0eb47bf41a345fbe6de4a65d9;p=emacs.git (Regexp Special): Nested repetition can be infloop. --- 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 The next alternative is for @samp{a*} to match only two @samp{a}s. With this choice, the rest of the regexp matches successfully.@refill -Nested repetition operators can be extremely slow if they specify -backtracking loops. For example, it could take hours for the regular -expression @samp{\(x+y*\)*a} to try to match the sequence -@samp{xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxz}, before it ultimately fails. -The slowness is because Emacs must try each imaginable way of grouping -the 35 @samp{x}s before concluding that none of them can work. To make -sure your regular expressions run fast, check nested repetitions +Nested repetition operators can be extremely slow or loop infinitely +if they use repetition operators inside repetition operators. For +example, it could take hours for the regular expression +@samp{\(x+y*\)*a} to try to match the sequence +@samp{xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxz}, before it ultimately +fails. Emacs must try each way of grouping the 35 @samp{x}s before +concluding that none of them can work. Even worse, @samp{\(x*\)*} can +match the null string in infinitely many ways, so it causes an +infinite loop. To avoid these problems, check nested repetitions carefully. @item @samp{+}