CVSROOT: /webcvs/grep Module name: grep Changes by: Jim Meyering <meyering> 16/02/05 00:44:53
Index: html_node/Character-Classes-and-Bracket-Expressions.html =================================================================== RCS file: /webcvs/grep/grep/manual/html_node/Character-Classes-and-Bracket-Expressions.html,v retrieving revision 1.21 retrieving revision 1.22 diff -u -b -r1.21 -r1.22 --- html_node/Character-Classes-and-Bracket-Expressions.html 2 Nov 2015 02:54:31 -0000 1.21 +++ html_node/Character-Classes-and-Bracket-Expressions.html 5 Feb 2016 00:44:51 -0000 1.22 @@ -1,166 +1,269 @@ -<html lang="en"> +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> +<html> +<!-- This manual is for grep, a pattern matching engine. + +Copyright (C) 1999-2002, 2005, 2008-2016 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". --> +<!-- Created by GNU Texinfo 6.0, http://www.gnu.org/software/texinfo/ --> <head> -<title>Character Classes and Bracket Expressions - GNU Grep 2.22</title> +<title>GNU Grep 2.23: Character Classes and Bracket Expressions</title> + +<meta name="description" content="GNU Grep 2.23: Character Classes and Bracket Expressions"> +<meta name="keywords" content="GNU Grep 2.23: Character Classes and Bracket Expressions"> +<meta name="resource-type" content="document"> +<meta name="distribution" content="global"> +<meta name="Generator" content="makeinfo"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> -<meta name="description" content="GNU Grep 2.22"> -<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"> +<link href="index.html#Top" rel="start" title="Top"> +<link href="Index.html#Index" rel="index" title="Index"> +<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents"> +<link href="Regular-Expressions.html#Regular-Expressions" rel="up" title="Regular Expressions"> +<link href="The-Backslash-Character-and-Special-Expressions.html#The-Backslash-Character-and-Special-Expressions" rel="next" title="The Backslash Character and Special Expressions"> +<link href="Fundamental-Structure.html#Fundamental-Structure" rel="prev" title="Fundamental Structure"> +<style type="text/css"> <!-- -This manual is for `grep', a pattern matching engine. +a.summary-letter {text-decoration: none} +blockquote.indentedblock {margin-right: 0em} +blockquote.smallindentedblock {margin-right: 0em; font-size: smaller} +blockquote.smallquotation {font-size: smaller} +div.display {margin-left: 3.2em} +div.example {margin-left: 3.2em} +div.lisp {margin-left: 3.2em} +div.smalldisplay {margin-left: 3.2em} +div.smallexample {margin-left: 3.2em} +div.smalllisp {margin-left: 3.2em} +kbd {font-style: oblique} +pre.display {font-family: inherit} +pre.format {font-family: inherit} +pre.menu-comment {font-family: serif} +pre.menu-preformatted {font-family: serif} +pre.smalldisplay {font-family: inherit; font-size: smaller} +pre.smallexample {font-size: smaller} +pre.smallformat {font-family: inherit; font-size: smaller} +pre.smalllisp {font-size: smaller} +span.nocodebreak {white-space: nowrap} +span.nolinebreak {white-space: nowrap} +span.roman {font-family: serif; font-weight: normal} +span.sansserif {font-family: sans-serif; font-weight: normal} +ul.no-bullet {list-style: none} +--> +</style> +<link rel="stylesheet" type="text/css" href="/software/gnulib/manual.css"> -Copyright (C) 1999-2002, 2005, 2008-2015 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> -<link rel="stylesheet" type="text/css" href="/software/gnulib/manual.css"> </head> -<body> -<div class="node"> + +<body lang="en"> <a name="Character-Classes-and-Bracket-Expressions"></a> +<div class="header"> <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> +Next: <a href="The-Backslash-Character-and-Special-Expressions.html#The-Backslash-Character-and-Special-Expressions" accesskey="n" rel="next">The Backslash Character and Special Expressions</a>, Previous: <a href="Fundamental-Structure.html#Fundamental-Structure" accesskey="p" rel="prev">Fundamental Structure</a>, Up: <a href="Regular-Expressions.html#Regular-Expressions" accesskey="u" rel="up">Regular Expressions</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p> </div> - +<hr> +<a name="Character-Classes-and-Bracket-Expressions-1"></a> <h3 class="section">3.2 Character Classes and Bracket Expressions</h3> -<p><a name="index-bracket-expression-217"></a><a name="index-character-class-218"></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>’. +<a name="index-bracket-expression"></a> +<a name="index-character-class"></a> +<p>A <em>bracket expression</em> is a list of characters enclosed by ‘<samp>[</samp>’ and +‘<samp>]</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>’, +if the first character of the list is the caret ‘<samp>^</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-219"></a>Within a bracket expression, a <dfn>range expression</dfn> consists of two +‘<samp>[0123456789]</samp>’ matches any single digit. +</p> +<a name="index-range-expression"></a> +<p>Within a bracket expression, a <em>range expression</em> consists of two characters separated by a hyphen. It matches any single character that sorts between the two characters, inclusive. In the default C locale, the sorting sequence is the native character -order; for example, ‘<samp><span class="samp">[a-d]</span></samp>’ is equivalent to ‘<samp><span class="samp">[abcd]</span></samp>’. +order; for example, ‘<samp>[a-d]</samp>’ is equivalent to ‘<samp>[abcd]</samp>’. In other locales, the sorting sequence is not specified, and -‘<samp><span class="samp">[a-d]</span></samp>’ might be equivalent to ‘<samp><span class="samp">[abcd]</span></samp>’ or to -‘<samp><span class="samp">[aBbCcDd]</span></samp>’, or it might fail to match any character, or the set of +‘<samp>[a-d]</samp>’ might be equivalent to ‘<samp>[abcd]</samp>’ or to +‘<samp>[aBbCcDd]</samp>’, or it might fail to match any character, or the set of characters that it matches might even be erratic. 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 +of bracket expressions, you can use the ‘<samp>C</samp>’ locale by setting the +<code>LC_ALL</code> environment variable to the value ‘<samp>C</samp>’. +</p> +<p>Finally, certain named classes of characters are predefined within bracket expressions, as follows. -Their interpretation depends on the <samp><span class="env">LC_CTYPE</span></samp> locale; -for example, ‘<samp><span class="samp">[[:alnum:]]</span></samp>’ means the character class of numbers and letters +Their interpretation depends on the <code>LC_CTYPE</code> locale; +for example, ‘<samp>[[:alnum:]]</samp>’ means the character class of numbers and letters in the current locale. - - <p><a name="index-classes-of-characters-220"></a><a name="index-character-classes-221"></a> - <dl> -<dt>‘<samp><span class="samp">[:alnum:]</span></samp>’<dd><a name="index-alnum-_0040r_007bcharacter-class_007d-222"></a><a name="index-alphanumeric-characters-223"></a>Alphanumeric characters: -‘<samp><span class="samp">[:alpha:]</span></samp>’ and ‘<samp><span class="samp">[:digit:]</span></samp>’; in the ‘<samp><span class="samp">C</span></samp>’ locale and ASCII -character encoding, this is the same as ‘<samp><span class="samp">[0-9A-Za-z]</span></samp>’. - - <br><dt>‘<samp><span class="samp">[:alpha:]</span></samp>’<dd><a name="index-alpha-_0040r_007bcharacter-class_007d-224"></a><a name="index-alphabetic-characters-225"></a>Alphabetic characters: -‘<samp><span class="samp">[:lower:]</span></samp>’ and ‘<samp><span class="samp">[:upper:]</span></samp>’; in the ‘<samp><span class="samp">C</span></samp>’ locale and ASCII -character encoding, this is the same as ‘<samp><span class="samp">[A-Za-z]</span></samp>’. - - <br><dt>‘<samp><span class="samp">[:blank:]</span></samp>’<dd><a name="index-blank-_0040r_007bcharacter-class_007d-226"></a><a name="index-blank-characters-227"></a>Blank characters: +</p> +<a name="index-classes-of-characters"></a> +<a name="index-character-classes"></a> +<dl compact="compact"> +<dt>‘<samp>[:alnum:]</samp>’</dt> +<dd><a name="index-alnum-character-class"></a> +<a name="index-alphanumeric-characters"></a> +<p>Alphanumeric characters: +‘<samp>[:alpha:]</samp>’ and ‘<samp>[:digit:]</samp>’; in the ‘<samp>C</samp>’ locale and ASCII +character encoding, this is the same as ‘<samp>[0-9A-Za-z]</samp>’. +</p> +</dd> +<dt>‘<samp>[:alpha:]</samp>’</dt> +<dd><a name="index-alpha-character-class"></a> +<a name="index-alphabetic-characters"></a> +<p>Alphabetic characters: +‘<samp>[:lower:]</samp>’ and ‘<samp>[:upper:]</samp>’; in the ‘<samp>C</samp>’ locale and ASCII +character encoding, this is the same as ‘<samp>[A-Za-z]</samp>’. +</p> +</dd> +<dt>‘<samp>[:blank:]</samp>’</dt> +<dd><a name="index-blank-character-class"></a> +<a name="index-blank-characters"></a> +<p>Blank characters: space and tab. - - <br><dt>‘<samp><span class="samp">[:cntrl:]</span></samp>’<dd><a name="index-cntrl-_0040r_007bcharacter-class_007d-228"></a><a name="index-control-characters-229"></a>Control characters. +</p> +</dd> +<dt>‘<samp>[:cntrl:]</samp>’</dt> +<dd><a name="index-cntrl-character-class"></a> +<a name="index-control-characters"></a> +<p>Control characters. In ASCII, these characters have octal codes 000 through 037, and 177 (DEL). 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-230"></a><a name="index-digit-characters-231"></a><a name="index-numeric-characters-232"></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-233"></a><a name="index-graphic-characters-234"></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-235"></a><a name="index-lower_002dcase-letters-236"></a>Lower-case letters; in the ‘<samp><span class="samp">C</span></samp>’ locale and ASCII character +</p> +</dd> +<dt>‘<samp>[:digit:]</samp>’</dt> +<dd><a name="index-digit-character-class"></a> +<a name="index-digit-characters"></a> +<a name="index-numeric-characters"></a> +<p>Digits: <code>0 1 2 3 4 5 6 7 8 9</code>. +</p> +</dd> +<dt>‘<samp>[:graph:]</samp>’</dt> +<dd><a name="index-graph-character-class"></a> +<a name="index-graphic-characters"></a> +<p>Graphical characters: +‘<samp>[:alnum:]</samp>’ and ‘<samp>[:punct:]</samp>’. +</p> +</dd> +<dt>‘<samp>[:lower:]</samp>’</dt> +<dd><a name="index-lower-character-class"></a> +<a name="index-lower_002dcase-letters"></a> +<p>Lower-case letters; in the ‘<samp>C</samp>’ locale and ASCII character encoding, this is <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-237"></a><a name="index-printable-characters-238"></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-239"></a><a name="index-punctuation-characters-240"></a>Punctuation characters; in the ‘<samp><span class="samp">C</span></samp>’ locale and ASCII character +</p> +</dd> +<dt>‘<samp>[:print:]</samp>’</dt> +<dd><a name="index-print-character-class"></a> +<a name="index-printable-characters"></a> +<p>Printable characters: +‘<samp>[:alnum:]</samp>’, ‘<samp>[:punct:]</samp>’, and space. +</p> +</dd> +<dt>‘<samp>[:punct:]</samp>’</dt> +<dd><a name="index-punct-character-class"></a> +<a name="index-punctuation-characters"></a> +<p>Punctuation characters; in the ‘<samp>C</samp>’ locale and ASCII character encoding, this is -<code>! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { | } ~</code>. - - <br><dt>‘<samp><span class="samp">[:space:]</span></samp>’<dd><a name="index-space-_0040r_007bcharacter-class_007d-241"></a><a name="index-space-characters-242"></a><a name="index-whitespace-characters-243"></a>Space characters: in the ‘<samp><span class="samp">C</span></samp>’ locale, this is +<code>! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { | } ~</code>. +</p> +</dd> +<dt>‘<samp>[:space:]</samp>’</dt> +<dd><a name="index-space-character-class"></a> +<a name="index-space-characters"></a> +<a name="index-whitespace-characters"></a> +<p>Space characters: in the ‘<samp>C</samp>’ locale, this is tab, newline, vertical tab, form feed, carriage return, and space. See <a href="Usage.html#Usage">Usage</a>, for more discussion of matching newlines. - - <br><dt>‘<samp><span class="samp">[:upper:]</span></samp>’<dd><a name="index-upper-_0040r_007bcharacter-class_007d-244"></a><a name="index-upper_002dcase-letters-245"></a>Upper-case letters: in the ‘<samp><span class="samp">C</span></samp>’ locale and ASCII character +</p> +</dd> +<dt>‘<samp>[:upper:]</samp>’</dt> +<dd><a name="index-upper-character-class"></a> +<a name="index-upper_002dcase-letters"></a> +<p>Upper-case letters: in the ‘<samp>C</samp>’ locale and ASCII character encoding, this is <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-246"></a><a name="index-xdigit-class-247"></a><a name="index-hexadecimal-digits-248"></a>Hexadecimal digits: +</p> +</dd> +<dt>‘<samp>[:xdigit:]</samp>’</dt> +<dd><a name="index-xdigit-character-class"></a> +<a name="index-xdigit-class"></a> +<a name="index-hexadecimal-digits"></a> +<p>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> - Note that the brackets in these class names are +</p> +</dd> +</dl> +<p>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><a name="invalid_002dbracket_002dexpr"></a>If you mistakenly omit the outer brackets, and search for say, ‘<samp><span class="samp">[:upper:]</span></samp>’, -GNU <samp><span class="command">grep</span></samp> prints a diagnostic and exits with status 2, on +</p> +<a name="invalid_002dbracket_002dexpr"></a><p>If you mistakenly omit the outer brackets, and search for say, ‘<samp>[:upper:]</samp>’, +GNU <code>grep</code> prints a diagnostic and exits with status 2, on the assumption that you did not intend to search for the nominally -equivalent regular expression: ‘<samp><span class="samp">[:epru]</span></samp>’. -Set the <samp><span class="env">POSIXLY_CORRECT</span></samp> environment variable to disable this feature. - - <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, +equivalent regular expression: ‘<samp>[:epru]</samp>’. +Set the <code>POSIXLY_CORRECT</code> environment variable to disable this feature. +</p> +<p>Most meta-characters lose their special meaning inside bracket expressions. +</p> +<dl compact="compact"> +<dt>‘<samp>]</samp>’</dt> +<dd><p>ends the bracket expression if it’s not the first list item. +So, if you want to make the ‘<samp>]</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 +</p> +</dd> +<dt>‘<samp>[.</samp>’</dt> +<dd><p>represents the open collating symbol. +</p> +</dd> +<dt>‘<samp>.]</samp>’</dt> +<dd><p>represents the close collating symbol. +</p> +</dd> +<dt>‘<samp>[=</samp>’</dt> +<dd><p>represents the open equivalence class. +</p> +</dd> +<dt>‘<samp>=]</samp>’</dt> +<dd><p>represents the close equivalence class. +</p> +</dd> +<dt>‘<samp>[:</samp>’</dt> +<dd><p>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 +</p> +</dd> +<dt>‘<samp>:]</samp>’</dt> +<dd><p>represents the close character class symbol. +</p> +</dd> +<dt>‘<samp>-</samp>’</dt> +<dd><p>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>’ +</p> +</dd> +<dt>‘<samp>^</samp>’</dt> +<dd><p>represents the characters not in the list. +If you want to make the ‘<samp>^</samp>’ character a list item, place it anywhere but first. +</p> +</dd> +</dl> + +<hr> +<div class="header"> +<p> +Next: <a href="The-Backslash-Character-and-Special-Expressions.html#The-Backslash-Character-and-Special-Expressions" accesskey="n" rel="next">The Backslash Character and Special Expressions</a>, Previous: <a href="Fundamental-Structure.html#Fundamental-Structure" accesskey="p" rel="prev">Fundamental Structure</a>, Up: <a href="Regular-Expressions.html#Regular-Expressions" accesskey="u" rel="up">Regular Expressions</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p> +</div> - </dl> - </body></html> +</body> +</html>
