1 |
@c -*-texinfo-*- |
@c -*-texinfo-*- |
2 |
@c This is part of the GNU Emacs Lisp Reference Manual. |
@c This is part of the GNU Emacs Lisp Reference Manual. |
3 |
@c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999 |
@c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999 |
4 |
@c Free Software Foundation, Inc. |
@c Free Software Foundation, Inc. |
5 |
@c See the file elisp.texi for copying conditions. |
@c See the file elisp.texi for copying conditions. |
6 |
@setfilename ../info/searching |
@setfilename ../info/searching |
7 |
@node Searching and Matching, Syntax Tables, Non-ASCII Characters, Top |
@node Searching and Matching, Syntax Tables, Non-ASCII Characters, Top |
325 |
is @samp{@var{c}..?\377}, the other is @samp{@var{c1}..@var{c2}}, where |
is @samp{@var{c}..?\377}, the other is @samp{@var{c1}..@var{c2}}, where |
326 |
@var{c1} is the first character of the charset to which @var{c2} |
@var{c1} is the first character of the charset to which @var{c2} |
327 |
belongs. |
belongs. |
328 |
|
|
329 |
You cannot always match all non-@sc{ascii} characters with the regular |
You cannot always match all non-@sc{ascii} characters with the regular |
330 |
expression @code{"[\200-\377]"}. This works when searching a unibyte |
expression @code{"[\200-\377]"}. This works when searching a unibyte |
331 |
buffer or string (@pxref{Text Representations}), but not in a multibyte |
buffer or string (@pxref{Text Representations}), but not in a multibyte |
483 |
surrounding @samp{\( @dots{} \)} grouping can limit the grouping power of |
surrounding @samp{\( @dots{} \)} grouping can limit the grouping power of |
484 |
@samp{\|}.@refill |
@samp{\|}.@refill |
485 |
|
|
486 |
Full backtracking capability exists to handle multiple uses of |
If you need full backtracking capability to handle multiple uses of |
487 |
@samp{\|}, if you use the POSIX regular expression functions |
@samp{\|}, use the POSIX regular expression functions (@pxref{POSIX |
488 |
(@pxref{POSIX Regexps}). |
Regexps}). |
489 |
|
|
490 |
@item \@{@var{m}\@} |
@item \@{@var{m}\@} |
491 |
is a postfix operator that repeats the previous pattern exactly @var{m} |
is a postfix operator that repeats the previous pattern exactly @var{m} |
532 |
This last application is not a consequence of the idea of a |
This last application is not a consequence of the idea of a |
533 |
parenthetical grouping; it is a separate feature that was assigned as a |
parenthetical grouping; it is a separate feature that was assigned as a |
534 |
second meaning to the same @samp{\( @dots{} \)} construct because, in |
second meaning to the same @samp{\( @dots{} \)} construct because, in |
535 |
pratice, there was usually no conflict between the two meanings. But |
practice, there was usually no conflict between the two meanings. But |
536 |
occasionally there is a conflict, and that led to the introduction of |
occasionally there is a conflict, and that led to the introduction of |
537 |
shy groups. |
shy groups. |
538 |
|
|
670 |
|
|
671 |
Here is a complicated regexp, used by Emacs to recognize the end of a |
Here is a complicated regexp, used by Emacs to recognize the end of a |
672 |
sentence together with any whitespace that follows. It is the value of |
sentence together with any whitespace that follows. It is the value of |
673 |
the variable @code{sentence-end}. |
the variable @code{sentence-end}. |
674 |
|
|
675 |
First, we show the regexp as a string in Lisp syntax to distinguish |
First, we show the regexp as a string in Lisp syntax to distinguish |
676 |
spaces from tab characters. The string constant begins and ends with a |
spaces from tab characters. The string constant begins and ends with a |
689 |
@example |
@example |
690 |
@group |
@group |
691 |
sentence-end |
sentence-end |
692 |
@result{} "[.?!][]\"')@}]*\\($\\| $\\| \\| \\)[ |
@result{} "[.?!][]\"')@}]*\\($\\| $\\| \\| \\)[ |
693 |
]*" |
]*" |
694 |
@end group |
@end group |
695 |
@end example |
@end example |
959 |
match, as required by POSIX. This is much slower, so use these |
match, as required by POSIX. This is much slower, so use these |
960 |
functions only when you really need the longest match. |
functions only when you really need the longest match. |
961 |
|
|
962 |
|
The POSIX search and match functions do not properly support the |
963 |
|
non-greedy repetition operators. This is because POSIX backtracking |
964 |
|
conflicts with the semantics of non-greedy repetition. |
965 |
|
|
966 |
@defun posix-search-forward regexp &optional limit noerror repeat |
@defun posix-search-forward regexp &optional limit noerror repeat |
967 |
This is like @code{re-search-forward} except that it performs the full |
This is like @code{re-search-forward} except that it performs the full |
968 |
backtracking specified by the POSIX standard for regular expression |
backtracking specified by the POSIX standard for regular expression |
1064 |
@section Search and Replace |
@section Search and Replace |
1065 |
@cindex replacement |
@cindex replacement |
1066 |
|
|
1067 |
@defun perform-replace from-string replacements start end query-flag regexp-flag delimited-flag &optional repeat-count map |
@defun perform-replace from-string replacements query-flag regexp-flag delimited-flag &optional repeat-count map start end |
1068 |
This function is the guts of @code{query-replace} and related |
This function is the guts of @code{query-replace} and related |
1069 |
commands. It searches for occurrences of @var{from-string} in the |
commands. It searches for occurrences of @var{from-string} in the |
1070 |
text between positions @var{start} and @var{end} and replaces some or |
text between positions @var{start} and @var{end} and replaces some or |
1071 |
all of them. If @var{start} is @code{nil}, point is used instead, and |
all of them. If @var{start} is @code{nil} (or omitted), point is used |
1072 |
the buffer's end is used for @var{end}. |
instead, and the buffer's end is used for @var{end}. |
1073 |
|
|
1074 |
If @var{query-flag} is @code{nil}, it replaces all |
If @var{query-flag} is @code{nil}, it replaces all |
1075 |
occurrences; otherwise, it asks the user what to do about each one. |
occurrences; otherwise, it asks the user what to do about each one. |
1259 |
@subsection Simple Match Data Access |
@subsection Simple Match Data Access |
1260 |
|
|
1261 |
This section explains how to use the match data to find out what was |
This section explains how to use the match data to find out what was |
1262 |
matched by the last search or match operation. |
matched by the last search or match operation, if it succeeded. |
1263 |
|
|
1264 |
You can ask about the entire matching text, or about a particular |
You can ask about the entire matching text, or about a particular |
1265 |
parenthetical subexpression of a regular expression. The @var{count} |
parenthetical subexpression of a regular expression. The @var{count} |
1277 |
|
|
1278 |
A search which fails may or may not alter the match data. In the |
A search which fails may or may not alter the match data. In the |
1279 |
past, a failing search did not do this, but we may change it in the |
past, a failing search did not do this, but we may change it in the |
1280 |
future. |
future. So don't try to rely on the value of the match data after |
1281 |
|
a failing search. |
1282 |
|
|
1283 |
@defun match-string count &optional in-string |
@defun match-string count &optional in-string |
1284 |
This function returns, as a string, the text matched in the last search |
This function returns, as a string, the text matched in the last search |
1330 |
@group |
@group |
1331 |
(string-match "\\(qu\\)\\(ick\\)" |
(string-match "\\(qu\\)\\(ick\\)" |
1332 |
"The quick fox jumped quickly.") |
"The quick fox jumped quickly.") |
1333 |
;0123456789 |
;0123456789 |
1334 |
@result{} 4 |
@result{} 4 |
1335 |
@end group |
@end group |
1336 |
|
|