CVSROOT: /web/grep Module name: grep Changes by: Karl Berry <karl> 09/05/24 18:43:01
Index: manual/html_node/Character-Classes-and-Bracket-Expressions.html =================================================================== RCS file: manual/html_node/Character-Classes-and-Bracket-Expressions.html diff -N manual/html_node/Character-Classes-and-Bracket-Expressions.html --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ manual/html_node/Character-Classes-and-Bracket-Expressions.html 24 May 2009 18:42:58 -0000 1.1 @@ -0,0 +1,156 @@ +<html lang="en"> +<head> +<title>Character Classes and Bracket Expressions - GNU Grep 2.5.4</title> +<meta http-equiv="Content-Type" content="text/html"> +<meta name="description" content="GNU Grep 2.5.4"> +<meta name="generator" content="makeinfo 4.13"> +<link title="Top" rel="start" href="index.html#Top"> +<link rel="up" href="Regular-Expressions.html#Regular-Expressions" title="Regular Expressions"> +<link rel="prev" href="Fundamental-Structure.html#Fundamental-Structure" title="Fundamental Structure"> +<link rel="next" href="The-Backslash-Character-and-Special-Expressions.html#The-Backslash-Character-and-Special-Expressions" title="The Backslash Character and Special Expressions"> +<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> +<!-- +This manual is for `grep', a pattern matching engine. + +Copyright (C) 1999, 2000, 2001, 2002, 2005, 2008, 2009 Free +Software Foundation, Inc. + + Permission is granted to copy, distribute and/or modify this + document under the terms of the GNU Free Documentation License, + Version 1.3 or any later version published by the Free Software + Foundation; with no Invariant Sections, with no Front-Cover Texts, + and with no Back-Cover Texts. A copy of the license is included + in the section entitled ``GNU Free Documentation License''. + --> +<meta http-equiv="Content-Style-Type" content="text/css"> +<style type="text/css"><!-- + pre.display { font-family:inherit } + pre.format { font-family:inherit } + pre.smalldisplay { font-family:inherit; font-size:smaller } + pre.smallformat { font-family:inherit; font-size:smaller } + pre.smallexample { font-size:smaller } + pre.smalllisp { font-size:smaller } + span.sc { font-variant:small-caps } + span.roman { font-family:serif; font-weight:normal; } + span.sansserif { font-family:sans-serif; font-weight:normal; } +--></style> +</head> +<body> +<div class="node"> +<a name="Character-Classes-and-Bracket-Expressions"></a> +<p> +Next: <a rel="next" accesskey="n" href="The-Backslash-Character-and-Special-Expressions.html#The-Backslash-Character-and-Special-Expressions">The Backslash Character and Special Expressions</a>, +Previous: <a rel="previous" accesskey="p" href="Fundamental-Structure.html#Fundamental-Structure">Fundamental Structure</a>, +Up: <a rel="up" accesskey="u" href="Regular-Expressions.html#Regular-Expressions">Regular Expressions</a> +<hr> +</div> + +<h3 class="section">3.2 Character Classes and Bracket Expressions</h3> + +<p><a name="index-bracket-expression-203"></a><a name="index-character-class-204"></a>A <dfn>bracket expression</dfn> is a list of characters enclosed by ‘<samp><span class="samp">[</span></samp>’ and +‘<samp><span class="samp">]</span></samp>’. +It matches any single character in that list; +if the first character of the list is the caret ‘<samp><span class="samp">^</span></samp>’, +then it matches any character <strong>not</strong> in the list. +For example, the regular expression +‘<samp><span class="samp">[0123456789]</span></samp>’ matches any single digit. + + <p><a name="index-range-expression-205"></a>Within a bracket expression, a <dfn>range expression</dfn> consists of two +characters separated by a hyphen. +It matches any single character that +sorts between the two characters, inclusive, using the locale's +collating sequence and character set. +For example, in the default C +locale, ‘<samp><span class="samp">[a-d]</span></samp>’ is equivalent to ‘<samp><span class="samp">[abcd]</span></samp>’. +Many locales sort +characters in dictionary order, and in these locales ‘<samp><span class="samp">[a-d]</span></samp>’ is +typically not equivalent to ‘<samp><span class="samp">[abcd]</span></samp>’; +it might be equivalent to ‘<samp><span class="samp">[aBbCcDd]</span></samp>’, for example. +To obtain the traditional interpretation +of bracket expressions, you can use the ‘<samp><span class="samp">C</span></samp>’ locale by setting the +<samp><span class="env">LC_ALL</span></samp> environment variable to the value ‘<samp><span class="samp">C</span></samp>’. + + <p>Finally, certain named classes of characters are predefined within +bracket expressions, as follows. +Their interpretation depends on the <code>LC_CTYPE</code> locale; +the interpretation below is that of the ‘<samp><span class="samp">C</span></samp>’ locale, +which is the default if no <code>LC_CTYPE</code> locale is specified. + + <p><a name="index-classes-of-characters-206"></a><a name="index-character-classes-207"></a> + <dl> +<dt>‘<samp><span class="samp">[:alnum:]</span></samp>’<dd><a name="index-alnum-_0040r_007bcharacter-class_007d-208"></a><a name="index-alphanumeric-characters-209"></a>Alphanumeric characters: +‘<samp><span class="samp">[:alpha:]</span></samp>’ and ‘<samp><span class="samp">[:digit:]</span></samp>’. + + <br><dt>‘<samp><span class="samp">[:alpha:]</span></samp>’<dd><a name="index-alpha-_0040r_007bcharacter-class_007d-210"></a><a name="index-alphabetic-characters-211"></a>Alphabetic characters: +‘<samp><span class="samp">[:lower:]</span></samp>’ and ‘<samp><span class="samp">[:upper:]</span></samp>’. + + <br><dt>‘<samp><span class="samp">[:blank:]</span></samp>’<dd><a name="index-blank-_0040r_007bcharacter-class_007d-212"></a><a name="index-blank-characters-213"></a>Blank characters: +space and tab. + + <br><dt>‘<samp><span class="samp">[:cntrl:]</span></samp>’<dd><a name="index-cntrl-_0040r_007bcharacter-class_007d-214"></a><a name="index-control-characters-215"></a>Control characters. +In <span class="sc">ascii</span>, these characters have octal codes 000 +through 037, and 177 (<code>DEL</code>). +In other character sets, these are +the equivalent characters, if any. + + <br><dt>‘<samp><span class="samp">[:digit:]</span></samp>’<dd><a name="index-digit-_0040r_007bcharacter-class_007d-216"></a><a name="index-digit-characters-217"></a><a name="index-numeric-characters-218"></a>Digits: <code>0 1 2 3 4 5 6 7 8 9</code>. + + <br><dt>‘<samp><span class="samp">[:graph:]</span></samp>’<dd><a name="index-graph-_0040r_007bcharacter-class_007d-219"></a><a name="index-graphic-characters-220"></a>Graphical characters: +‘<samp><span class="samp">[:alnum:]</span></samp>’ and ‘<samp><span class="samp">[:punct:]</span></samp>’. + + <br><dt>‘<samp><span class="samp">[:lower:]</span></samp>’<dd><a name="index-lower-_0040r_007bcharacter-class_007d-221"></a><a name="index-lower_002dcase-letters-222"></a>Lower-case letters: +<code>a b c d e f g h i j k l m n o p q r s t u v w x y z</code>. + + <br><dt>‘<samp><span class="samp">[:print:]</span></samp>’<dd><a name="index-print-_0040r_007bcharacter-class_007d-223"></a><a name="index-printable-characters-224"></a>Printable characters: +‘<samp><span class="samp">[:alnum:]</span></samp>’, ‘<samp><span class="samp">[:punct:]</span></samp>’, and space. + + <br><dt>‘<samp><span class="samp">[:punct:]</span></samp>’<dd><a name="index-punct-_0040r_007bcharacter-class_007d-225"></a><a name="index-punctuation-characters-226"></a>Punctuation characters: +<code>! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { | } ~</code>. + + <br><dt>‘<samp><span class="samp">[:space:]</span></samp>’<dd><a name="index-space-_0040r_007bcharacter-class_007d-227"></a><a name="index-space-characters-228"></a><a name="index-whitespace-characters-229"></a>Space characters: +tab, newline, vertical tab, form feed, carriage return, and space. + + <br><dt>‘<samp><span class="samp">[:upper:]</span></samp>’<dd><a name="index-upper-_0040r_007bcharacter-class_007d-230"></a><a name="index-upper_002dcase-letters-231"></a>Upper-case letters: +<code>A B C D E F G H I J K L M N O P Q R S T U V W X Y Z</code>. + + <br><dt>‘<samp><span class="samp">[:xdigit:]</span></samp>’<dd><a name="index-xdigit-_0040r_007bcharacter-class_007d-232"></a><a name="index-xdigit-class-233"></a><a name="index-hexadecimal-digits-234"></a>Hexadecimal digits: +<code>0 1 2 3 4 5 6 7 8 9 A B C D E F a b c d e f</code>. + + </dl> + For example, ‘<samp><span class="samp">[[:alnum:]]</span></samp>’ means ‘<samp><span class="samp">[0-9A-Za-z]</span></samp>’, except the latter +depends upon the ‘<samp><span class="samp">C</span></samp>’ locale and the <span class="sc">ascii</span> character +encoding, whereas the former is independent of locale and character set. +(Note that the brackets in these class names are +part of the symbolic names, and must be included in addition to +the brackets delimiting the bracket expression.) + + <p>Most meta-characters lose their special meaning inside bracket expressions. + + <dl> +<dt>‘<samp><span class="samp">]</span></samp>’<dd>ends the bracket expression if it's not the first list item. +So, if you want to make the ‘<samp><span class="samp">]</span></samp>’ character a list item, +you must put it first. + + <br><dt>‘<samp><span class="samp">[.</span></samp>’<dd>represents the open collating symbol. + + <br><dt>‘<samp><span class="samp">.]</span></samp>’<dd>represents the close collating symbol. + + <br><dt>‘<samp><span class="samp">[=</span></samp>’<dd>represents the open equivalence class. + + <br><dt>‘<samp><span class="samp">=]</span></samp>’<dd>represents the close equivalence class. + + <br><dt>‘<samp><span class="samp">[:</span></samp>’<dd>represents the open character class symbol, and should be followed by a valid character class name. + + <br><dt>‘<samp><span class="samp">:]</span></samp>’<dd>represents the close character class symbol. + + <br><dt>‘<samp><span class="samp">-</span></samp>’<dd>represents the range if it's not first or last in a list or the ending point +of a range. + + <br><dt>‘<samp><span class="samp">^</span></samp>’<dd>represents the characters not in the list. +If you want to make the ‘<samp><span class="samp">^</span></samp>’ +character a list item, place it anywhere but first. + + </dl> + + </body></html> +
