Commit 473f8eb3 authored by Richard M. Stallman's avatar Richard M. Stallman
Browse files

(Regexp Special): Nested repetition can be infloop.

parent d6702947
...@@ -244,13 +244,15 @@ first tries to match all three @samp{a}s; but the rest of the pattern is ...@@ -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 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 this choice, the rest of the regexp matches successfully.@refill
Nested repetition operators can be extremely slow if they specify Nested repetition operators can be extremely slow or loop infinitely
backtracking loops. For example, it could take hours for the regular if they use repetition operators inside repetition operators. For
expression @samp{\(x+y*\)*a} to try to match the sequence example, it could take hours for the regular expression
@samp{xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxz}, before it ultimately fails. @samp{\(x+y*\)*a} to try to match the sequence
The slowness is because Emacs must try each imaginable way of grouping @samp{xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxz}, before it ultimately
the 35 @samp{x}s before concluding that none of them can work. To make fails. Emacs must try each way of grouping the 35 @samp{x}s before
sure your regular expressions run fast, check nested repetitions 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. carefully.
@item @samp{+} @item @samp{+}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment