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  // Code generated by mksyntaxgo from the RE2 distribution. DO NOT EDIT.
     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 [regexp.Compile] and [regexp.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  	(?<name>re)    named & numbered capturing group (submatch)
    60  	(?:re)         non-capturing group
    61  	(?flags)       set flags within current group; non-capturing
    62  	(?flags:re)    set flags during re; non-capturing
    63  
    64  	Flag syntax is xyz (set) or -xyz (clear) or xy-z (set xy, clear z). The flags are:
    65  
    66  	i              case-insensitive (default false)
    67  	m              multi-line mode: ^ and $ match begin/end line in addition to begin/end text (default false)
    68  	s              let . match \n (default false)
    69  	U              ungreedy: swap meaning of x* and x*?, x+ and x+?, etc (default false)
    70  
    71  Empty strings:
    72  
    73  	^              at beginning of text or line (flag m=true)
    74  	$              at end of text (like \z not \Z) or line (flag m=true)
    75  	\A             at beginning of text
    76  	\b             at ASCII word boundary (\w on one side and \W, \A, or \z on the other)
    77  	\B             not at ASCII word boundary
    78  	\z             at end of text
    79  
    80  Escape sequences:
    81  
    82  	\a             bell (== \007)
    83  	\f             form feed (== \014)
    84  	\t             horizontal tab (== \011)
    85  	\n             newline (== \012)
    86  	\r             carriage return (== \015)
    87  	\v             vertical tab character (== \013)
    88  	\*             literal *, for any punctuation character *
    89  	\123           octal character code (up to three digits)
    90  	\x7F           hex character code (exactly two digits)
    91  	\x{10FFFF}     hex character code
    92  	\Q...\E        literal text ... even if ... has punctuation
    93  
    94  Character class elements:
    95  
    96  	x              single character
    97  	A-Z            character range (inclusive)
    98  	\d             Perl character class
    99  	[:foo:]        ASCII character class foo
   100  	\p{Foo}        Unicode character class Foo
   101  	\pF            Unicode character class F (one-letter name)
   102  
   103  Named character classes as character class elements:
   104  
   105  	[\d]           digits (== \d)
   106  	[^\d]          not digits (== \D)
   107  	[\D]           not digits (== \D)
   108  	[^\D]          not not digits (== \d)
   109  	[[:name:]]     named ASCII class inside character class (== [:name:])
   110  	[^[:name:]]    named ASCII class inside negated character class (== [:^name:])
   111  	[\p{Name}]     named Unicode property inside character class (== \p{Name})
   112  	[^\p{Name}]    named Unicode property inside negated character class (== \P{Name})
   113  
   114  Perl character classes (all ASCII-only):
   115  
   116  	\d             digits (== [0-9])
   117  	\D             not digits (== [^0-9])
   118  	\s             whitespace (== [\t\n\f\r ])
   119  	\S             not whitespace (== [^\t\n\f\r ])
   120  	\w             word characters (== [0-9A-Za-z_])
   121  	\W             not word characters (== [^0-9A-Za-z_])
   122  
   123  ASCII character classes:
   124  
   125  	[[:alnum:]]    alphanumeric (== [0-9A-Za-z])
   126  	[[:alpha:]]    alphabetic (== [A-Za-z])
   127  	[[:ascii:]]    ASCII (== [\x00-\x7F])
   128  	[[:blank:]]    blank (== [\t ])
   129  	[[:cntrl:]]    control (== [\x00-\x1F\x7F])
   130  	[[:digit:]]    digits (== [0-9])
   131  	[[:graph:]]    graphical (== [!-~] == [A-Za-z0-9!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~])
   132  	[[:lower:]]    lower case (== [a-z])
   133  	[[:print:]]    printable (== [ -~] == [ [:graph:]])
   134  	[[:punct:]]    punctuation (== [!-/:-@[-`{-~])
   135  	[[:space:]]    whitespace (== [\t\n\v\f\r ])
   136  	[[:upper:]]    upper case (== [A-Z])
   137  	[[:word:]]     word characters (== [0-9A-Za-z_])
   138  	[[:xdigit:]]   hex digit (== [0-9A-Fa-f])
   139  
   140  Unicode character classes are those in [unicode.Categories] and [unicode.Scripts].
   141  */
   142  package syntax
   143  

View as plain text