Mercurial > emacs
comparison lispref/searching.texi @ 8469:9e44c96dd99d
entered into RCS
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sun, 07 Aug 1994 00:25:52 +0000 |
parents | bc548090f760 |
children | 6b8e51b286c6 |
comparison
equal
deleted
inserted
replaced
8468:52940ba43041 | 8469:9e44c96dd99d |
---|---|
531 This regular expression contains four parts in succession and can be | 531 This regular expression contains four parts in succession and can be |
532 deciphered as follows: | 532 deciphered as follows: |
533 | 533 |
534 @table @code | 534 @table @code |
535 @item [.?!] | 535 @item [.?!] |
536 The first part of the pattern consists of three characters, a period, a | 536 The first part of the pattern is a character set that matches any one of |
537 question mark and an exclamation mark, within square brackets. The | 537 three characters: period, question mark, and exclamation mark. The |
538 match must begin with one of these three characters. | 538 match must begin with one of these three characters. |
539 | 539 |
540 @item []\"')@}]* | 540 @item []\"')@}]* |
541 The second part of the pattern matches any closing braces and quotation | 541 The second part of the pattern matches any closing braces and quotation |
542 marks, zero or more of them, that may follow the period, question mark | 542 marks, zero or more of them, that may follow the period, question mark |
543 or exclamation mark. The @code{\"} is Lisp syntax for a double-quote in | 543 or exclamation mark. The @code{\"} is Lisp syntax for a double-quote in |
544 a string. The @samp{*} at the end indicates that the immediately | 544 a string. The @samp{*} at the end indicates that the immediately |
545 preceding regular expression (a character set, in this case) may be | 545 preceding regular expression (a character set, in this case) may be |
546 repeated zero or more times. | 546 repeated zero or more times. |
547 | 547 |
548 @item \\($\\|@ \\|\t\\|@ @ \\) | 548 @item \\($\\|@ $\\|\t\\|@ @ \\) |
549 The third part of the pattern matches the whitespace that follows the | 549 The third part of the pattern matches the whitespace that follows the |
550 end of a sentence: the end of a line, or a tab, or two spaces. The | 550 end of a sentence: the end of a line, or a tab, or two spaces. The |
551 double backslashes mark the parentheses and vertical bars as regular | 551 double backslashes mark the parentheses and vertical bars as regular |
552 expression syntax; the parentheses mark the group and the vertical bars | 552 expression syntax; the parentheses delimit a group and the vertical bars |
553 separate alternatives. The dollar sign is used to match the end of a | 553 separate alternatives. The dollar sign is used to match the end of a |
554 line. | 554 line. |
555 | 555 |
556 @item [ \t\n]* | 556 @item [ \t\n]* |
557 Finally, the last part of the pattern matches any additional whitespace | 557 Finally, the last part of the pattern matches any additional whitespace |
622 @deffn Command re-search-backward regexp &optional limit noerror repeat | 622 @deffn Command re-search-backward regexp &optional limit noerror repeat |
623 This function searches backward in the current buffer for a string of | 623 This function searches backward in the current buffer for a string of |
624 text that is matched by the regular expression @var{regexp}, leaving | 624 text that is matched by the regular expression @var{regexp}, leaving |
625 point at the beginning of the first text found. | 625 point at the beginning of the first text found. |
626 | 626 |
627 This function is analogous to @code{re-search-forward}, but they are | 627 This function is analogous to @code{re-search-forward}, but they are not |
628 not simple mirror images. @code{re-search-forward} finds the match | 628 simple mirror images. @code{re-search-forward} finds the match whose |
629 whose beginning is as close as possible. If @code{re-search-backward} | 629 beginning is as close as possible to the starting point. If |
630 were a perfect mirror image, it would find the match whose end is as | 630 @code{re-search-backward} were a perfect mirror image, it would find the |
631 close as possible. However, in fact it finds the match whose beginning | 631 match whose end is as close as possible. However, in fact it finds the |
632 is as close as possible. The reason is that matching a regular | 632 match whose beginning is as close as possible. The reason is that |
633 expression at a given spot always works from beginning to end, and is | 633 matching a regular expression at a given spot always works from |
634 done at a specified beginning position. | 634 beginning to end, and starts at a specified beginning position. |
635 | 635 |
636 A true mirror-image of @code{re-search-forward} would require a special | 636 A true mirror-image of @code{re-search-forward} would require a special |
637 feature for matching regexps from end to beginning. It's not worth the | 637 feature for matching regexps from end to beginning. It's not worth the |
638 trouble of implementing that. | 638 trouble of implementing that. |
639 @end deffn | 639 @end deffn |
802 If @var{repeat-count} is non-@code{nil}, it should be an integer, the | 802 If @var{repeat-count} is non-@code{nil}, it should be an integer, the |
803 number of occurrences to consider. In this case, @code{perform-replace} | 803 number of occurrences to consider. In this case, @code{perform-replace} |
804 returns after considering that many occurrences. | 804 returns after considering that many occurrences. |
805 | 805 |
806 Normally, the keymap @code{query-replace-map} defines the possible user | 806 Normally, the keymap @code{query-replace-map} defines the possible user |
807 responses. The argument @var{map}, if non-@code{nil}, is a keymap to | 807 responses for queries. The argument @var{map}, if non-@code{nil}, is a |
808 use instead of @code{query-replace-map}. | 808 keymap to use instead of @code{query-replace-map}. |
809 @end defun | 809 @end defun |
810 | 810 |
811 @defvar query-replace-map | 811 @defvar query-replace-map |
812 This variable holds a special keymap that defines the valid user | 812 This variable holds a special keymap that defines the valid user |
813 responses for @code{query-replace} and related functions, as well as | 813 responses for @code{query-replace} and related functions, as well as |
835 | 835 |
836 @item skip | 836 @item skip |
837 Do not take action for this question---in other words, ``no.'' | 837 Do not take action for this question---in other words, ``no.'' |
838 | 838 |
839 @item exit | 839 @item exit |
840 Answer this question ``no,'' and don't ask any more. | 840 Answer this question ``no,'' and give up on the entire series of |
841 questions, assuming that the answers will be ``no.'' | |
841 | 842 |
842 @item act-and-exit | 843 @item act-and-exit |
843 Answer this question ``yes,'' and don't ask any more. | 844 Answer this question ``yes,'' and give up on the entire series of |
845 questions, assuming that subsequent answers will be ``no.'' | |
844 | 846 |
845 @item act-and-show | 847 @item act-and-show |
846 Answer this question ``yes,'' but show the results---don't advance yet | 848 Answer this question ``yes,'' but show the results---don't advance yet |
847 to the next question. | 849 to the next question. |
848 | 850 |
906 | 908 |
907 @defun match-beginning count | 909 @defun match-beginning count |
908 This function returns the position of the start of text matched by the | 910 This function returns the position of the start of text matched by the |
909 last regular expression searched for, or a subexpression of it. | 911 last regular expression searched for, or a subexpression of it. |
910 | 912 |
911 The argument @var{count}, a number, specifies a subexpression whose | 913 If @var{count} is zero, then the value is the position of the start of |
912 start position is the value. If @var{count} is zero, then the value is | 914 the text matched by the whole regexp. Otherwise, @var{count}, specifies |
913 the position of the text matched by the whole regexp. If @var{count} is | 915 a subexpression in the regular expresion. The value of the function is |
914 greater than zero, then the value is the position of the beginning of | 916 the starting position of the match for that subexpression. |
915 the text matched by the @var{count}th subexpression. | |
916 | 917 |
917 Subexpressions of a regular expression are those expressions grouped | 918 Subexpressions of a regular expression are those expressions grouped |
918 inside of parentheses, @samp{\(@dots{}\)}. The @var{count}th | 919 with escaped parentheses, @samp{\(@dots{}\)}. The @var{count}th |
919 subexpression is found by counting occurrences of @samp{\(} from the | 920 subexpression is found by counting occurrences of @samp{\(} from the |
920 beginning of the whole regular expression. The first subexpression is | 921 beginning of the whole regular expression. The first subexpression is |
921 numbered 1, the second 2, and so on. | 922 numbered 1, the second 2, and so on. |
922 | 923 |
923 The value is @code{nil} for a parenthetical grouping inside of a | 924 The value is @code{nil} for a subexpression inside a |
924 @samp{\|} alternative that wasn't used in the match. | 925 @samp{\|} alternative that wasn't used in the match. |
925 @end defun | 926 @end defun |
926 | 927 |
927 @defun match-end count | 928 @defun match-end count |
928 This function returns the position of the end of the text that matched | 929 This function returns the position of the end of the text that matched |
970 @group | 971 @group |
971 (list | 972 (list |
972 (re-search-forward "The \\(cat \\)") | 973 (re-search-forward "The \\(cat \\)") |
973 (match-beginning 0) | 974 (match-beginning 0) |
974 (match-beginning 1)) | 975 (match-beginning 1)) |
975 @result{} (t 9 13) | 976 @result{} (9 9 13) |
976 @end group | 977 @end group |
977 | 978 |
978 @group | 979 @group |
979 ---------- Buffer: foo ---------- | 980 ---------- Buffer: foo ---------- |
980 I read "The cat @point{}in the hat comes back" twice. | 981 I read "The cat @point{}in the hat comes back" twice. |
1009 capitalized, then the first word of the replacement text is capitalized. | 1010 capitalized, then the first word of the replacement text is capitalized. |
1010 If the original text contains just one word, and that word is a capital | 1011 If the original text contains just one word, and that word is a capital |
1011 letter, @code{replace-match} considers this a capitalized first word | 1012 letter, @code{replace-match} considers this a capitalized first word |
1012 rather than all upper case. | 1013 rather than all upper case. |
1013 | 1014 |
1015 If @code{case-replace} is @code{nil}, then case conversion is not done, | |
1016 regardless of the value of @var{fixed-case}. @xref{Searching and Case}. | |
1017 | |
1014 If @var{literal} is non-@code{nil}, then @var{replacement} is inserted | 1018 If @var{literal} is non-@code{nil}, then @var{replacement} is inserted |
1015 exactly as it is, the only alterations being case changes as needed. | 1019 exactly as it is, the only alterations being case changes as needed. |
1016 If it is @code{nil} (the default), then the character @samp{\} is treated | 1020 If it is @code{nil} (the default), then the character @samp{\} is treated |
1017 specially. If a @samp{\} appears in @var{replacement}, then it must be | 1021 specially. If a @samp{\} appears in @var{replacement}, then it must be |
1018 part of one of the following sequences: | 1022 part of one of the following sequences: |
1022 @cindex @samp{&} in replacement | 1026 @cindex @samp{&} in replacement |
1023 @samp{\&} stands for the entire text being replaced. | 1027 @samp{\&} stands for the entire text being replaced. |
1024 | 1028 |
1025 @item @samp{\@var{n}} | 1029 @item @samp{\@var{n}} |
1026 @cindex @samp{\@var{n}} in replacement | 1030 @cindex @samp{\@var{n}} in replacement |
1027 @samp{\@var{n}} stands for the text that matched the @var{n}th | 1031 @samp{\@var{n}}, where @var{n} is a digit, stands for the text that |
1028 subexpression in the original regexp. Subexpressions are those | 1032 matched the @var{n}th subexpression in the original regexp. |
1029 expressions grouped inside of @samp{\(@dots{}\)}. @var{n} is a digit. | 1033 Subexpressions are those expressions grouped inside @samp{\(@dots{}\)}. |
1030 | 1034 |
1031 @item @samp{\\} | 1035 @item @samp{\\} |
1032 @cindex @samp{\} in replacement | 1036 @cindex @samp{\} in replacement |
1033 @samp{\\} stands for a single @samp{\} in the replacement text. | 1037 @samp{\\} stands for a single @samp{\} in the replacement text. |
1034 @end table | 1038 @end table |
1180 particular character sets, are included: thus, @samp{[aB]} would match | 1184 particular character sets, are included: thus, @samp{[aB]} would match |
1181 @samp{a} or @samp{A} or @samp{b} or @samp{B}. | 1185 @samp{a} or @samp{A} or @samp{b} or @samp{B}. |
1182 | 1186 |
1183 If you do not want this feature, set the variable | 1187 If you do not want this feature, set the variable |
1184 @code{case-fold-search} to @code{nil}. Then all letters must match | 1188 @code{case-fold-search} to @code{nil}. Then all letters must match |
1185 exactly, including case. This is a per-buffer-local variable; altering | 1189 exactly, including case. This is a buffer-local variable; altering the |
1186 the variable affects only the current buffer. (@xref{Intro to | 1190 variable affects only the current buffer. (@xref{Intro to |
1187 Buffer-Local}.) Alternatively, you may change the value of | 1191 Buffer-Local}.) Alternatively, you may change the value of |
1188 @code{default-case-fold-search}, which is the default value of | 1192 @code{default-case-fold-search}, which is the default value of |
1189 @code{case-fold-search} for buffers that do not override it. | 1193 @code{case-fold-search} for buffers that do not override it. |
1190 | 1194 |
1191 Note that the user-level incremental search feature handles case | 1195 Note that the user-level incremental search feature handles case |
1193 a match of either case, but when given an upper case letter, it looks | 1197 a match of either case, but when given an upper case letter, it looks |
1194 for an upper case letter only. But this has nothing to do with the | 1198 for an upper case letter only. But this has nothing to do with the |
1195 searching functions Lisp functions use. | 1199 searching functions Lisp functions use. |
1196 | 1200 |
1197 @defopt case-replace | 1201 @defopt case-replace |
1198 This variable determines whether @code{query-replace} should preserve | 1202 This variable determines whether the replacement functions should |
1199 case in replacements. If the variable is @code{nil}, then | 1203 preserve case. If the variable is @code{nil}, that means to use the |
1200 @code{replace-match} should not try to convert case. | 1204 replacement text verbatim. A non-@code{nil} value means to convert the |
1205 case of the replacement text according to the text being replaced. | |
1206 | |
1207 The function @code{replace-match} is where this variable actually has | |
1208 its effect. @xref{Replacing Match}. | |
1201 @end defopt | 1209 @end defopt |
1202 | 1210 |
1203 @defopt case-fold-search | 1211 @defopt case-fold-search |
1204 This buffer-local variable determines whether searches should ignore | 1212 This buffer-local variable determines whether searches should ignore |
1205 case. If the variable is @code{nil} they do not ignore case; otherwise | 1213 case. If the variable is @code{nil} they do not ignore case; otherwise |
1220 This section describes some variables that hold regular expressions | 1228 This section describes some variables that hold regular expressions |
1221 used for certain purposes in editing: | 1229 used for certain purposes in editing: |
1222 | 1230 |
1223 @defvar page-delimiter | 1231 @defvar page-delimiter |
1224 This is the regexp describing line-beginnings that separate pages. The | 1232 This is the regexp describing line-beginnings that separate pages. The |
1225 default value is @code{"^\014"} (i.e., @code{"^^L"} or @code{"^\C-l"}). | 1233 default value is @code{"^\014"} (i.e., @code{"^^L"} or @code{"^\C-l"}); |
1234 this matches a line that starts with a formfeed character. | |
1226 @end defvar | 1235 @end defvar |
1227 | 1236 |
1228 @defvar paragraph-separate | 1237 @defvar paragraph-separate |
1229 This is the regular expression for recognizing the beginning of a line | 1238 This is the regular expression for recognizing the beginning of a line |
1230 that separates paragraphs. (If you change this, you may have to | 1239 that separates paragraphs. (If you change this, you may have to |
1231 change @code{paragraph-start} also.) The default value is @code{"^[ | 1240 change @code{paragraph-start} also.) The default value is |
1232 \t\f]*$"}, which is a line that consists entirely of spaces, tabs, and | 1241 @w{@code{"^[@ \t\f]*$"}}, which matches a line that consists entirely of |
1233 form feeds. | 1242 spaces, tabs, and form feeds. |
1234 @end defvar | 1243 @end defvar |
1235 | 1244 |
1236 @defvar paragraph-start | 1245 @defvar paragraph-start |
1237 This is the regular expression for recognizing the beginning of a line | 1246 This is the regular expression for recognizing the beginning of a line |
1238 that starts @emph{or} separates paragraphs. The default value is | 1247 that starts @emph{or} separates paragraphs. The default value is |
1239 @code{"^[ \t\n\f]"}, which matches a line starting with a space, tab, | 1248 @w{@code{"^[@ \t\n\f]"}}, which matches a line starting with a space, tab, |
1240 newline, or form feed. | 1249 newline, or form feed. |
1241 @end defvar | 1250 @end defvar |
1242 | 1251 |
1243 @defvar sentence-end | 1252 @defvar sentence-end |
1244 This is the regular expression describing the end of a sentence. (All | 1253 This is the regular expression describing the end of a sentence. (All |
1245 paragraph boundaries also end sentences, regardless.) The default value | 1254 paragraph boundaries also end sentences, regardless.) The default value |
1246 is: | 1255 is: |
1247 | 1256 |
1248 @example | 1257 @example |
1249 "[.?!][]\"')@}]*\\($\\|\t\\| \\)[ \t\n]*" | 1258 "[.?!][]\"')@}]*\\($\\| $\\|\t\\| \\)[ \t\n]*" |
1250 @end example | 1259 @end example |
1251 | 1260 |
1252 This means a period, question mark or exclamation mark, followed by a | 1261 This means a period, question mark or exclamation mark, followed |
1253 closing brace, followed by tabs, spaces or new lines. | 1262 optionally by a closing parenthetical character, followed by tabs, |
1263 spaces or new lines. | |
1254 | 1264 |
1255 For a detailed explanation of this regular expression, see @ref{Regexp | 1265 For a detailed explanation of this regular expression, see @ref{Regexp |
1256 Example}. | 1266 Example}. |
1257 @end defvar | 1267 @end defvar |