1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
<h4 class="subsection">Syntax of Regular Expressions</h4> <p>Regular expressions have a syntax in which a few characters are special constructs and the rest are <em>ordinary</em>. An ordinary character is a simple regular expression that matches that character and nothing else. The special characters are ‘<samp>.</samp>’, ‘<samp>*</samp>’, ‘<samp>+</samp>’, ‘<samp>?</samp>’, ‘<samp>[</samp>’, ‘<samp>^</samp>’, ‘<samp>$</samp>’, and ‘<samp>\</samp>’; no new special characters will be defined in the future. The character ‘<samp>]</samp>’ is special if it ends a character alternative (see later). The character ‘<samp>-</samp>’ is special inside a character alternative. A ‘<samp>[:</samp>’ and balancing ‘<samp>:]</samp>’ enclose a character class inside a character alternative. Any other character appearing in a regular expression is ordinary, unless a ‘<samp>\</samp>’ precedes it. </p> <p>For example, ‘<samp>f</samp>’ is not a special character, so it is ordinary, and therefore ‘<samp>f</samp>’ is a regular expression that matches the string ‘<samp>f</samp>’ and no other string. (It does <em>not</em> match the string ‘<samp>fg</samp>’, but it does match a <em>part</em> of that string.) Likewise, ‘<samp>o</samp>’ is a regular expression that matches only ‘<samp>o</samp>’. </p> <p>Any two regular expressions <var>a</var> and <var>b</var> can be concatenated. The result is a regular expression that matches a string if <var>a</var> matches some amount of the beginning of that string and <var>b</var> matches the rest of the string. </p> <p>As a simple example, we can concatenate the regular expressions ‘<samp>f</samp>’ and ‘<samp>o</samp>’ to get the regular expression ‘<samp>fo</samp>’, which matches only the string ‘<samp>fo</samp>’. Still trivial. To do something more powerful, you need to use one of the special regular expression constructs. </p> <table class="menu" border="0" cellspacing="0"> <tr>
<td align="left" valign="top">• <a href="regexp-special" accesskey="1">Regexp Special</a>
</td>
<td> </td>
<td align="left" valign="top">Special characters in regular expressions. </td>
</tr> <tr>
<td align="left" valign="top">• <a href="char-classes" accesskey="2">Char Classes</a>
</td>
<td> </td>
<td align="left" valign="top">Character classes used in regular expressions. </td>
</tr> <tr>
<td align="left" valign="top">• <a href="regexp-backslash" accesskey="3">Regexp Backslash</a>
</td>
<td> </td>
<td align="left" valign="top">Backslash-sequences in regular expressions. </td>
</tr> </table><div class="_attribution">
<p class="_attribution-p">
Copyright © 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/Syntax-of-Regexps.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Syntax-of-Regexps.html</a>
</p>
</div>
|