Source file src/regexp/syntax/doc.go

     1  // Copyright 2012 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // DO NOT EDIT. This file is generated by mksyntaxgo from the RE2 distribution.
     6  
     7  /*
     8  Package syntax parses regular expressions into parse trees and compiles
     9  parse trees into programs. Most clients of regular expressions will use the
    10  facilities of package regexp (such as Compile and Match) instead of this package.
    11  
    12  # Syntax
    13  
    14  The regular expression syntax understood by this package when parsing with the Perl flag is as follows.
    15  Parts of the syntax can be disabled by passing alternate flags to Parse.
    16  
    17  Single characters:
    18  
    19  	.              any character, possibly including newline (flag s=true)
    20  	[xyz]          character class
    21  	[^xyz]         negated character class
    22  	\d             Perl character class
    23  	\D             negated Perl character class
    24  	[[:alpha:]]    ASCII character class
    25  	[[:^alpha:]]   negated ASCII character class
    26  	\pN            Unicode character class (one-letter name)
    27  	\p{Greek}      Unicode character class
    28  	\PN            negated Unicode character class (one-letter name)
    29  	\P{Greek}      negated Unicode character class
    30  
    31  Composites:
    32  
    33  	xy             x followed by y
    34  	x|y            x or y (prefer x)
    35  
    36  Repetitions:
    37  
    38  	x*             zero or more x, prefer more
    39  	x+             one or more x, prefer more
    40  	x?             zero or one x, prefer one
    41  	x{n,m}         n or n+1 or ... or m x, prefer more
    42  	x{n,}          n or more x, prefer more
    43  	x{n}           exactly n x
    44  	x*?            zero or more x, prefer fewer
    45  	x+?            one or more x, prefer fewer
    46  	x??            zero or one x, prefer zero
    47  	x{n,m}?        n or n+1 or ... or m x, prefer fewer
    48  	x{n,}?         n or more x, prefer fewer
    49  	x{n}?          exactly n x
    50  
    51  Implementation restriction: The counting forms x{n,m}, x{n,}, and x{n}
    52  reject forms that create a minimum or maximum repetition count above 1000.
    53  Unlimited repetitions are not subject to this restriction.
    54  
    55  Grouping:
    56  
    57  	(re)           numbered capturing group (submatch)
    58  	(?P<name>re)   named & numbered capturing group (submatch)
    59  	(?:re)         non-capturing group
    60  	(?flags)       set flags within current group; non-capturing
    61  	(?flags:re)    set flags during re; non-capturing
    62  
    63  	Flag syntax is xyz (set) or -xyz (clear) or xy-z (set xy, clear z). The flags are:
    64  
    65  	i              case-insensitive (default false)
    66  	m              multi-line mode: ^ and $ match begin/end line in addition to begin/end text (default false)
    67  	s              let . match \n (default false)
    68  	U              ungreedy: swap meaning of x* and x*?, x+ and x+?, etc (default false)
    69  
    70  Empty strings:
    71  
    72  	^              at beginning of text or line (flag m=true)
    73  	$              at end of text (like \z not \Z) or line (flag m=true)
    74  	\A             at beginning of text
    75  	\b             at ASCII word boundary (\w on one side and \W, \A, or \z on the other)
    76  	\B             not at ASCII word boundary
    77  	\z             at end of text
    78  
    79  Escape sequences:
    80  
    81  	\a             bell (== \007)
    82  	\f             form feed (== \014)
    83  	\t             horizontal tab (== \011)
    84  	\n             newline (== \012)
    85  	\r             carriage return (== \015)
    86  	\v             vertical tab character (== \013)
    87  	\*             literal *, for any punctuation character *
    88  	\123           octal character code (up to three digits)
    89  	\x7F           hex character code (exactly two digits)
    90  	\x{10FFFF}     hex character code
    91  	\Q...\E        literal text ... even if ... has punctuation
    92  
    93  Character class elements:
    94  
    95  	x              single character
    96  	A-Z            character range (inclusive)
    97  	\d             Perl character class
    98  	[:foo:]        ASCII character class foo
    99  	\p{Foo}        Unicode character class Foo
   100  	\pF            Unicode character class F (one-letter name)
   101  
   102  Named character classes as character class elements:
   103  
   104  	[\d]           digits (== \d)
   105  	[^\d]          not digits (== \D)
   106  	[\D]           not digits (== \D)
   107  	[^\D]          not not digits (== \d)
   108  	[[:name:]]     named ASCII class inside character class (== [:name:])
   109  	[^[:name:]]    named ASCII class inside negated character class (== [:^name:])
   110  	[\p{Name}]     named Unicode property inside character class (== \p{Name})
   111  	[^\p{Name}]    named Unicode property inside negated character class (== \P{Name})
   112  
   113  Perl character classes (all ASCII-only):
   114  
   115  	\d             digits (== [0-9])
   116  	\D             not digits (== [^0-9])
   117  	\s             whitespace (== [\t\n\f\r ])
   118  	\S             not whitespace (== [^\t\n\f\r ])
   119  	\w             word characters (== [0-9A-Za-z_])
   120  	\W             not word characters (== [^0-9A-Za-z_])
   121  
   122  ASCII character classes:
   123  
   124  	[[:alnum:]]    alphanumeric (== [0-9A-Za-z])
   125  	[[:alpha:]]    alphabetic (== [A-Za-z])
   126  	[[:ascii:]]    ASCII (== [\x00-\x7F])
   127  	[[:blank:]]    blank (== [\t ])
   128  	[[:cntrl:]]    control (== [\x00-\x1F\x7F])
   129  	[[:digit:]]    digits (== [0-9])
   130  	[[:graph:]]    graphical (== [!-~] == [A-Za-z0-9!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~])
   131  	[[:lower:]]    lower case (== [a-z])
   132  	[[:print:]]    printable (== [ -~] == [ [:graph:]])
   133  	[[:punct:]]    punctuation (== [!-/:-@[-`{-~])
   134  	[[:space:]]    whitespace (== [\t\n\v\f\r ])
   135  	[[:upper:]]    upper case (== [A-Z])
   136  	[[:word:]]     word characters (== [0-9A-Za-z_])
   137  	[[:xdigit:]]   hex digit (== [0-9A-Fa-f])
   138  
   139  Unicode character classes are those in unicode.Categories and unicode.Scripts.
   140  */
   141  package syntax
   142  

View as plain text