summaryrefslogtreecommitdiff
path: root/devdocs/elisp/searching-and-case.html
blob: afbcf942314f8576daf43ac4bbbc67f6cab2ee45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
 <h3 class="section">Searching and Case</h3>  <p>By default, searches in Emacs ignore the case of the text they are searching through; if you specify searching for ‘<samp>FOO</samp>’, then ‘<samp>Foo</samp>’ or ‘<samp>foo</samp>’ is also considered a match. This applies to regular expressions, too; thus, ‘<samp>[aB]</samp>’ would match ‘<samp>a</samp>’ or ‘<samp>A</samp>’ or ‘<samp>b</samp>’ or ‘<samp>B</samp>’. </p> <p>If you do not want this feature, set the variable <code>case-fold-search</code> to <code>nil</code>. Then all letters must match exactly, including case. This is a buffer-local variable; altering the variable affects only the current buffer. (See <a href="intro-to-buffer_002dlocal">Intro to Buffer-Local</a>.) Alternatively, you may change the default value. In Lisp code, you will more typically use <code>let</code> to bind <code>case-fold-search</code> to the desired value. </p> <p>Note that the user-level incremental search feature handles case distinctions differently. When the search string contains only lower case letters, the search ignores case, but when the search string contains one or more upper case letters, the search becomes case-sensitive. But this has nothing to do with the searching functions used in Lisp code. See <a href="https://www.gnu.org/software/emacs/manual/html_node/emacs/Incremental-Search.html#Incremental-Search">Incremental Search</a> in <cite>The GNU Emacs Manual</cite>. </p> <dl> <dt id="case-fold-search">User Option: <strong>case-fold-search</strong>
</dt> <dd><p>This buffer-local variable determines whether searches should ignore case. If the variable is <code>nil</code> they do not ignore case; otherwise (and by default) they do ignore case. </p></dd>
</dl> <dl> <dt id="case-replace">User Option: <strong>case-replace</strong>
</dt> <dd>
<p>This variable determines whether the higher-level replacement functions should preserve case. If the variable is <code>nil</code>, that means to use the replacement text verbatim. A non-<code>nil</code> value means to convert the case of the replacement text according to the text being replaced. </p> <p>This variable is used by passing it as an argument to the function <code>replace-match</code>. See <a href="replacing-match">Replacing Match</a>. </p>
</dd>
</dl><div class="_attribution">
  <p class="_attribution-p">
    Copyright &copy; 1990-1996, 1998-2022 Free Software Foundation, Inc. <br>Licensed under the GNU GPL license.<br>
    <a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Searching-and-Case.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Searching-and-Case.html</a>
  </p>
</div>