diff options
| author | Richard M. Stallman | 2004-05-22 22:05:57 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 2004-05-22 22:05:57 +0000 |
| commit | 473f8eb3c9eccdd0eb47bf41a345fbe6de4a65d9 (patch) | |
| tree | 2c18096223672d67f9657a1bb4eba7007fe2572c | |
| parent | d67029478a1418211459bda6e5cba9981665dfbf (diff) | |
| download | emacs-473f8eb3c9eccdd0eb47bf41a345fbe6de4a65d9.tar.gz emacs-473f8eb3c9eccdd0eb47bf41a345fbe6de4a65d9.zip | |
(Regexp Special): Nested repetition can be infloop.
| -rw-r--r-- | lispref/searching.texi | 16 |
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 | |||
| 244 | The next alternative is for @samp{a*} to match only two @samp{a}s. With | 244 | The next alternative is for @samp{a*} to match only two @samp{a}s. With |
| 245 | this choice, the rest of the regexp matches successfully.@refill | 245 | this choice, the rest of the regexp matches successfully.@refill |
| 246 | 246 | ||
| 247 | Nested repetition operators can be extremely slow if they specify | 247 | Nested repetition operators can be extremely slow or loop infinitely |
| 248 | backtracking loops. For example, it could take hours for the regular | 248 | if they use repetition operators inside repetition operators. For |
| 249 | expression @samp{\(x+y*\)*a} to try to match the sequence | 249 | example, 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 |
| 251 | The slowness is because Emacs must try each imaginable way of grouping | 251 | @samp{xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxz}, before it ultimately |
| 252 | the 35 @samp{x}s before concluding that none of them can work. To make | 252 | fails. Emacs must try each way of grouping the 35 @samp{x}s before |
| 253 | sure your regular expressions run fast, check nested repetitions | 253 | concluding that none of them can work. Even worse, @samp{\(x*\)*} can |
| 254 | match the null string in infinitely many ways, so it causes an | ||
| 255 | infinite loop. To avoid these problems, check nested repetitions | ||
| 254 | carefully. | 256 | carefully. |
| 255 | 257 | ||
| 256 | @item @samp{+} | 258 | @item @samp{+} |