doc.go 5.5 KB

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