Mercurial > emacs
comparison man/search.texi @ 90224:2d92f5c9d6ae
Revision: miles@gnu.org--gnu-2005/emacs--unicode--0--patch-78
Merge from emacs--cvs-trunk--0
Patches applied:
* emacs--cvs-trunk--0 (patch 514-518)
- Update from CVS
- Merge from gnus--rel--5.10
* gnus--rel--5.10 (patch 104-105)
- Update from CVS
author | Miles Bader <miles@gnu.org> |
---|---|
date | Fri, 26 Aug 2005 09:51:52 +0000 |
parents | fbb2bea03df9 b0da9981adab |
children | a3716f7538f2 |
comparison
equal
deleted
inserted
replaced
90223:edf295560b5a | 90224:2d92f5c9d6ae |
---|---|
1 @c This is part of the Emacs manual. | 1 @c This is part of the Emacs manual. |
2 @c Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1997, 2000, 2001, 2004, 2005 | 2 @c Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1997, 2000, 2001, 2002, |
3 @c Free Software Foundation, Inc. | 3 @c 2003, 2004, 2005 Free Software Foundation, Inc. |
4 @c See file emacs.texi for copying conditions. | 4 @c See file emacs.texi for copying conditions. |
5 @node Search, Fixit, Display, Top | 5 @node Search, Fixit, Display, Top |
6 @chapter Searching and Replacement | 6 @chapter Searching and Replacement |
7 @cindex searching | 7 @cindex searching |
8 @cindex finding strings within text | 8 @cindex finding strings within text |
22 * Incremental Search:: Search happens as you type the string. | 22 * Incremental Search:: Search happens as you type the string. |
23 * Nonincremental Search:: Specify entire string and then search. | 23 * Nonincremental Search:: Specify entire string and then search. |
24 * Word Search:: Search for sequence of words. | 24 * Word Search:: Search for sequence of words. |
25 * Regexp Search:: Search for match for a regexp. | 25 * Regexp Search:: Search for match for a regexp. |
26 * Regexps:: Syntax of regular expressions. | 26 * Regexps:: Syntax of regular expressions. |
27 * Regexp Backslash:: Regular expression constructs starting with `\'. | |
28 * Regexp Example:: A complex regular expression explained. | |
27 * Search Case:: To ignore case while searching, or not. | 29 * Search Case:: To ignore case while searching, or not. |
28 * Replace:: Search, and replace some or all matches. | 30 * Replace:: Search, and replace some or all matches. |
29 * Other Repeating Search:: Operating on all matches for some regexp. | 31 * Other Repeating Search:: Operating on all matches for some regexp. |
30 @end menu | 32 @end menu |
31 | 33 |
208 @subsection Isearch for Non-@acronym{ASCII} Characters | 210 @subsection Isearch for Non-@acronym{ASCII} Characters |
209 | 211 |
210 @cindex searching for non-@acronym{ASCII} characters | 212 @cindex searching for non-@acronym{ASCII} characters |
211 @cindex input method, during incremental search | 213 @cindex input method, during incremental search |
212 | 214 |
213 To enter non-@acronym{ASCII} characters in an incrementral search, | 215 To enter non-@acronym{ASCII} characters in an incremental search, |
214 you must use an input method (@pxref{Input Methods}). If an input | 216 you must use an input method (@pxref{Input Methods}). If an input |
215 method is enabled in the current buffer when you start the search, you | 217 method is enabled in the current buffer when you start the search, you |
216 can use it while you type the search string also. Emacs indicates | 218 can use it while you type the search string also. Emacs indicates |
217 that by including the input method mnemonic in its prompt, like this: | 219 that by including the input method mnemonic in its prompt, like this: |
218 | 220 |
667 @samp{\}), and it introduces additional special constructs. | 669 @samp{\}), and it introduces additional special constructs. |
668 | 670 |
669 Because @samp{\} quotes special characters, @samp{\$} is a regular | 671 Because @samp{\} quotes special characters, @samp{\$} is a regular |
670 expression that matches only @samp{$}, and @samp{\[} is a regular | 672 expression that matches only @samp{$}, and @samp{\[} is a regular |
671 expression that matches only @samp{[}, and so on. | 673 expression that matches only @samp{[}, and so on. |
674 | |
675 See the following section for the special constructs that begin | |
676 with @samp{\}. | |
672 @end table | 677 @end table |
673 | 678 |
674 Note: for historical compatibility, special characters are treated as | 679 Note: for historical compatibility, special characters are treated as |
675 ordinary ones if they are in contexts where their special meanings make no | 680 ordinary ones if they are in contexts where their special meanings make no |
676 sense. For example, @samp{*foo} treats @samp{*} as ordinary since there is | 681 sense. For example, @samp{*foo} treats @samp{*} as ordinary since there is |
677 no preceding expression on which the @samp{*} can act. It is poor practice | 682 no preceding expression on which the @samp{*} can act. It is poor practice |
678 to depend on this behavior; it is better to quote the special character anyway, | 683 to depend on this behavior; it is better to quote the special character anyway, |
679 regardless of where it appears.@refill | 684 regardless of where it appears. |
680 | 685 |
681 For the most part, @samp{\} followed by any character matches only that | 686 @node Regexp Backslash |
682 character. However, there are several exceptions: two-character | 687 @section Backslash in Regular Expressions |
683 sequences starting with @samp{\} that have special meanings. The second | 688 |
684 character in the sequence is always an ordinary character when used on | 689 For the most part, @samp{\} followed by any character matches only |
685 its own. Here is a table of @samp{\} constructs. | 690 that character. However, there are several exceptions: two-character |
691 sequences starting with @samp{\} that have special meanings. The | |
692 second character in the sequence is always an ordinary character when | |
693 used on its own. Here is a table of @samp{\} constructs. | |
686 | 694 |
687 @table @kbd | 695 @table @kbd |
688 @item \| | 696 @item \| |
689 specifies an alternative. Two regular expressions @var{a} and @var{b} | 697 specifies an alternative. Two regular expressions @var{a} and @var{b} |
690 with @samp{\|} in between form an expression that matches some text if | 698 with @samp{\|} in between form an expression that matches some text if |
834 @end table | 842 @end table |
835 | 843 |
836 The constructs that pertain to words and syntax are controlled by the | 844 The constructs that pertain to words and syntax are controlled by the |
837 setting of the syntax table (@pxref{Syntax}). | 845 setting of the syntax table (@pxref{Syntax}). |
838 | 846 |
839 Here is a complicated regexp. It is a simplified version of the | 847 @node Regexp Example |
840 regexp that Emacs uses, by default, to recognize the end of a sentence | 848 @section Regular Expression Example |
849 | |
850 Here is a complicated regexp---a simplified version of the regexp | |
851 that Emacs uses, by default, to recognize the end of a sentence | |
841 together with any whitespace that follows. We show its Lisp syntax to | 852 together with any whitespace that follows. We show its Lisp syntax to |
842 distinguish the spaces from the tab characters. In Lisp syntax, the | 853 distinguish the spaces from the tab characters. In Lisp syntax, the |
843 string constant begins and ends with a double-quote. @samp{\"} stands | 854 string constant begins and ends with a double-quote. @samp{\"} stands |
844 for a double-quote as part of the regexp, @samp{\\} for a backslash as | 855 for a double-quote as part of the regexp, @samp{\\} for a backslash as |
845 part of the regexp, @samp{\t} for a tab, and @samp{\n} for a newline. | 856 part of the regexp, @samp{\t} for a tab, and @samp{\n} for a newline. |
861 @key{TAB} to enter a tab, and @kbd{C-j} to enter a newline. You would | 872 @key{TAB} to enter a tab, and @kbd{C-j} to enter a newline. You would |
862 also type single backslashes as themselves, instead of doubling them | 873 also type single backslashes as themselves, instead of doubling them |
863 for Lisp syntax. In commands that use ordinary minibuffer input to | 874 for Lisp syntax. In commands that use ordinary minibuffer input to |
864 read a regexp, you would quote the @kbd{C-j} by preceding it with a | 875 read a regexp, you would quote the @kbd{C-j} by preceding it with a |
865 @kbd{C-q} to prevent @kbd{C-j} from exiting the minibuffer. | 876 @kbd{C-q} to prevent @kbd{C-j} from exiting the minibuffer. |
866 | |
867 @ignore | |
868 @c I commented this out because it is missing vital information | |
869 @c and therefore useless. For instance, what do you do to *use* the | |
870 @c regular expression when it is finished? What jobs is this good for? | |
871 @c -- rms | |
872 | |
873 @findex re-builder | |
874 @cindex authoring regular expressions | |
875 For convenient interactive development of regular expressions, you | |
876 can use the @kbd{M-x re-builder} command. It provides a convenient | |
877 interface for creating regular expressions, by giving immediate visual | |
878 feedback. The buffer from which @code{re-builder} was invoked becomes | |
879 the target for the regexp editor, which pops in a separate window. At | |
880 all times, all the matches in the target buffer for the current | |
881 regular expression are highlighted. Each parenthesized sub-expression | |
882 of the regexp is shown in a distinct face, which makes it easier to | |
883 verify even very complex regexps. (On displays that don't support | |
884 colors, Emacs blinks the cursor around the matched text, as it does | |
885 for matching parens.) | |
886 @end ignore | |
887 | 877 |
888 @node Search Case | 878 @node Search Case |
889 @section Searching and Case | 879 @section Searching and Case |
890 | 880 |
891 Incremental searches in Emacs normally ignore the case of the text | 881 Incremental searches in Emacs normally ignore the case of the text |
925 @cindex global substitution | 915 @cindex global substitution |
926 | 916 |
927 Global search-and-replace operations are not needed often in Emacs, | 917 Global search-and-replace operations are not needed often in Emacs, |
928 but they are available. In addition to the simple @kbd{M-x | 918 but they are available. In addition to the simple @kbd{M-x |
929 replace-string} command which replaces all occurrences, | 919 replace-string} command which replaces all occurrences, |
930 there is a @kbd{M-x query-replace} command which finds each occurrence | 920 there is @kbd{M-%} (@code{query-replace}), which presents each occurrence |
931 of the pattern and asks you whether to replace it. | 921 of the pattern and asks you whether to replace it. |
932 | 922 |
933 The replace commands normally operate on the text from point to the | 923 The replace commands normally operate on the text from point to the |
934 end of the buffer; however, in Transient Mark mode (@pxref{Transient | 924 end of the buffer; however, in Transient Mark mode (@pxref{Transient |
935 Mark}), when the mark is active, they operate on the region. The | 925 Mark}), when the mark is active, they operate on the region. The |