diff options
| author | Richard M. Stallman | 2001-09-06 19:46:04 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 2001-09-06 19:46:04 +0000 |
| commit | a5d0a32e01523b1fd906bc36b62e2e3437e5f8cc (patch) | |
| tree | d79a60f5a8504a4abdc9e7b390d7c52a150bbb6e | |
| parent | 2a2048f2e24a87da51be10a06ccdff425eae4c51 (diff) | |
| download | emacs-a5d0a32e01523b1fd906bc36b62e2e3437e5f8cc.tar.gz emacs-a5d0a32e01523b1fd906bc36b62e2e3437e5f8cc.zip | |
Explain clearly what \digit does when that grouping
did not match.
| -rw-r--r-- | lispref/searching.texi | 42 |
1 files changed, 27 insertions, 15 deletions
diff --git a/lispref/searching.texi b/lispref/searching.texi index 4f0177592f5..a014080d845 100644 --- a/lispref/searching.texi +++ b/lispref/searching.texi | |||
| @@ -548,25 +548,35 @@ numbering of any ordinary, non-shy groups. | |||
| 548 | 548 | ||
| 549 | @item \@var{digit} | 549 | @item \@var{digit} |
| 550 | matches the same text that matched the @var{digit}th occurrence of a | 550 | matches the same text that matched the @var{digit}th occurrence of a |
| 551 | @samp{\( @dots{} \)} construct. | 551 | grouping (@samp{\( @dots{} \)}) construct. |
| 552 | 552 | ||
| 553 | In other words, after the end of a @samp{\( @dots{} \)} construct, the | 553 | In other words, after the end of a group, the matcher remembers the |
| 554 | matcher remembers the beginning and end of the text matched by that | 554 | beginning and end of the text matched by that group. Later on in the |
| 555 | construct. Then, later on in the regular expression, you can use | 555 | regular expression you can use @samp{\} followed by @var{digit} to |
| 556 | @samp{\} followed by @var{digit} to match that same text, whatever it | 556 | match that same text, whatever it may have been. |
| 557 | may have been. | ||
| 558 | 557 | ||
| 559 | The strings matching the first nine @samp{\( @dots{} \)} constructs | 558 | The strings matching the first nine grouping constructs appearing in |
| 560 | appearing in a regular expression are assigned numbers 1 through 9 in | 559 | the entire regular expression passed to a search or matching function |
| 561 | the order that the open parentheses appear in the regular expression. | 560 | are assigned numbers 1 through 9 in the order that the open |
| 562 | So you can use @samp{\1} through @samp{\9} to refer to the text matched | 561 | parentheses appear in the regular expression. So you can use |
| 563 | by the corresponding @samp{\( @dots{} \)} constructs. | 562 | @samp{\1} through @samp{\9} to refer to the text matched by the |
| 563 | corresponding grouping constructs. | ||
| 564 | 564 | ||
| 565 | For example, @samp{\(.*\)\1} matches any newline-free string that is | 565 | For example, @samp{\(.*\)\1} matches any newline-free string that is |
| 566 | composed of two identical halves. The @samp{\(.*\)} matches the first | 566 | composed of two identical halves. The @samp{\(.*\)} matches the first |
| 567 | half, which may be anything, but the @samp{\1} that follows must match | 567 | half, which may be anything, but the @samp{\1} that follows must match |
| 568 | the same exact text. | 568 | the same exact text. |
| 569 | 569 | ||
| 570 | If a particular grouping construct in the regular expression was never | ||
| 571 | matched---for instance, if it appears inside of an alternative that | ||
| 572 | wasn't used, or inside of a repetition that repeated zero times---then | ||
| 573 | the corresponding @samp{\@var{digit}} construct never matches | ||
| 574 | anything. To use an artificial example,, @samp{\(foo\(b*\)\|lose\)\2} | ||
| 575 | cannot match @samp{lose}: the second alternative inside the larger | ||
| 576 | group matches it, but then @samp{\2} is undefined and can't match | ||
| 577 | anything. But it can match @samp{foobb}, because the first | ||
| 578 | alternative matches @samp{foob} and @samp{\2} matches @samp{b}. | ||
| 579 | |||
| 570 | @item \w | 580 | @item \w |
| 571 | @cindex @samp{\w} in regexp | 581 | @cindex @samp{\w} in regexp |
| 572 | matches any word-constituent character. The editor syntax table | 582 | matches any word-constituent character. The editor syntax table |
| @@ -1266,9 +1276,7 @@ future. | |||
| 1266 | This function returns, as a string, the text matched in the last search | 1276 | This function returns, as a string, the text matched in the last search |
| 1267 | or match operation. It returns the entire text if @var{count} is zero, | 1277 | or match operation. It returns the entire text if @var{count} is zero, |
| 1268 | or just the portion corresponding to the @var{count}th parenthetical | 1278 | or just the portion corresponding to the @var{count}th parenthetical |
| 1269 | subexpression, if @var{count} is positive. If @var{count} is out of | 1279 | subexpression, if @var{count} is positive. |
| 1270 | range, or if that subexpression didn't match anything, the value is | ||
| 1271 | @code{nil}. | ||
| 1272 | 1280 | ||
| 1273 | If the last such operation was done against a string with | 1281 | If the last such operation was done against a string with |
| 1274 | @code{string-match}, then you should pass the same string as the | 1282 | @code{string-match}, then you should pass the same string as the |
| @@ -1277,6 +1285,10 @@ you should omit @var{in-string} or pass @code{nil} for it; but you | |||
| 1277 | should make sure that the current buffer when you call | 1285 | should make sure that the current buffer when you call |
| 1278 | @code{match-string} is the one in which you did the searching or | 1286 | @code{match-string} is the one in which you did the searching or |
| 1279 | matching. | 1287 | matching. |
| 1288 | |||
| 1289 | The value is @code{nil} if @var{count} is out of range, or for a | ||
| 1290 | subexpression inside a @samp{\|} alternative that wasn't used or a | ||
| 1291 | repetition that repeated zero times. | ||
| 1280 | @end defun | 1292 | @end defun |
| 1281 | 1293 | ||
| 1282 | @defun match-string-no-properties count &optional in-string | 1294 | @defun match-string-no-properties count &optional in-string |
| @@ -1294,7 +1306,7 @@ the regular expression, and the value of the function is the starting | |||
| 1294 | position of the match for that subexpression. | 1306 | position of the match for that subexpression. |
| 1295 | 1307 | ||
| 1296 | The value is @code{nil} for a subexpression inside a @samp{\|} | 1308 | The value is @code{nil} for a subexpression inside a @samp{\|} |
| 1297 | alternative that wasn't used in the match. | 1309 | alternative that wasn't used or a repetition that repeated zero times. |
| 1298 | @end defun | 1310 | @end defun |
| 1299 | 1311 | ||
| 1300 | @defun match-end count | 1312 | @defun match-end count |