Mercurial > emacs
comparison man/search.texi @ 64918:80b859b476aa
(Regexp Backslash, Regexp Example): New nodes split out of Regexps.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Thu, 11 Aug 2005 19:51:14 +0000 |
parents | 3723093a21fd |
children | 016c8310240c |
comparison
equal
deleted
inserted
replaced
64917:f9b024cc4772 | 64918:80b859b476aa |
---|---|
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 |
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 |