syntax_perl.qbk 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  1. [/
  2. Copyright 2006-2007 John Maddock.
  3. Distributed under the Boost Software License, Version 1.0.
  4. (See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt).
  6. ]
  7. [section:perl_syntax Perl Regular Expression Syntax]
  8. [h3 Synopsis]
  9. The Perl regular expression syntax is based on that used by the
  10. programming language Perl . Perl regular expressions are the
  11. default behavior in Boost.Regex or you can pass the flag [^perl] to the
  12. [basic_regex] constructor, for example:
  13. // e1 is a case sensitive Perl regular expression:
  14. // since Perl is the default option there's no need to explicitly specify the syntax used here:
  15. boost::regex e1(my_expression);
  16. // e2 a case insensitive Perl regular expression:
  17. boost::regex e2(my_expression, boost::regex::perl|boost::regex::icase);
  18. [h3 Perl Regular Expression Syntax]
  19. In Perl regular expressions, all characters match themselves except for the
  20. following special characters:
  21. [pre .\[{}()\\\*+?|^$]
  22. Other characters are special only in certain situations - for example `]` is special only after an opening `[`.
  23. [h4 Wildcard]
  24. The single character '.' when used outside of a character set will match
  25. any single character except:
  26. * The NULL character when the [link boost_regex.ref.match_flag_type flag
  27. [^match_not_dot_null]] is passed to the matching algorithms.
  28. * The newline character when the [link boost_regex.ref.match_flag_type
  29. flag [^match_not_dot_newline]] is passed to
  30. the matching algorithms.
  31. [h4 Anchors]
  32. A '^' character shall match the start of a line.
  33. A '$' character shall match the end of a line.
  34. [h4 Marked sub-expressions]
  35. A section beginning [^(] and ending [^)] acts as a marked sub-expression.
  36. Whatever matched the sub-expression is split out in a separate field by
  37. the matching algorithms. Marked sub-expressions can also repeated, or
  38. referred to by a back-reference.
  39. [h4 Non-marking grouping]
  40. A marked sub-expression is useful to lexically group part of a regular
  41. expression, but has the side-effect of spitting out an extra field in
  42. the result. As an alternative you can lexically group part of a
  43. regular expression, without generating a marked sub-expression by using
  44. [^(?:] and [^)] , for example [^(?:ab)+] will repeat [^ab] without splitting
  45. out any separate sub-expressions.
  46. [h4 Repeats]
  47. Any atom (a single character, a marked sub-expression, or a character class)
  48. can be repeated with the [^*], [^+], [^?], and [^{}] operators.
  49. The [^*] operator will match the preceding atom zero or more times,
  50. for example the expression [^a*b] will match any of the following:
  51. b
  52. ab
  53. aaaaaaaab
  54. The [^+] operator will match the preceding atom one or more times, for
  55. example the expression [^a+b] will match any of the following:
  56. ab
  57. aaaaaaaab
  58. But will not match:
  59. b
  60. The [^?] operator will match the preceding atom zero or one times, for
  61. example the expression ca?b will match any of the following:
  62. cb
  63. cab
  64. But will not match:
  65. caab
  66. An atom can also be repeated with a bounded repeat:
  67. [^a{n}] Matches 'a' repeated exactly n times.
  68. [^a{n,}] Matches 'a' repeated n or more times.
  69. [^a{n, m}] Matches 'a' repeated between n and m times inclusive.
  70. For example:
  71. [pre ^a{2,3}$]
  72. Will match either of:
  73. aa
  74. aaa
  75. But neither of:
  76. a
  77. aaaa
  78. Note that the "{" and "}" characters will treated as ordinary literals when used
  79. in a context that is not a repeat: this matches Perl 5.x behavior. For example in
  80. the expressions "ab{1", "ab1}" and "a{b}c" the curly brackets are all treated as
  81. literals and ['no error will be raised].
  82. It is an error to use a repeat operator, if the preceding construct can not
  83. be repeated, for example:
  84. a(*)
  85. Will raise an error, as there is nothing for the [^*] operator to be applied to.
  86. [h4 Non greedy repeats]
  87. The normal repeat operators are "greedy", that is to say they will consume as
  88. much input as possible. There are non-greedy versions available that will
  89. consume as little input as possible while still producing a match.
  90. [^*?] Matches the previous atom zero or more times, while consuming as little
  91. input as possible.
  92. [^+?] Matches the previous atom one or more times, while consuming as
  93. little input as possible.
  94. [^??] Matches the previous atom zero or one times, while consuming
  95. as little input as possible.
  96. [^{n,}?] Matches the previous atom n or more times, while consuming as
  97. little input as possible.
  98. [^{n,m}?] Matches the previous atom between n and m times, while
  99. consuming as little input as possible.
  100. [h4 Possessive repeats]
  101. By default when a repeated pattern does not match then the engine will backtrack until
  102. a match is found. However, this behaviour can sometime be undesireble so there are
  103. also "possessive" repeats: these match as much as possible and do not then allow
  104. backtracking if the rest of the expression fails to match.
  105. [^*+] Matches the previous atom zero or more times, while giving nothing back.
  106. [^++] Matches the previous atom one or more times, while giving nothing back.
  107. [^?+] Matches the previous atom zero or one times, while giving nothing back.
  108. [^{n,}+] Matches the previous atom n or more times, while giving nothing back.
  109. [^{n,m}+] Matches the previous atom between n and m times, while giving nothing back.
  110. [h4 Back references]
  111. An escape character followed by a digit /n/, where /n/ is in the range 1-9,
  112. matches the same string that was matched by sub-expression /n/. For example
  113. the expression:
  114. [pre ^(a\*)\[\^a\]\*\\1$]
  115. Will match the string:
  116. aaabbaaa
  117. But not the string:
  118. aaabba
  119. You can also use the \g escape for the same function, for example:
  120. [table
  121. [[Escape][Meaning]]
  122. [[[^\g1]][Match whatever matched sub-expression 1]]
  123. [[[^\g{1}]][Match whatever matched sub-expression 1: this form allows for safer
  124. parsing of the expression in cases like [^\g{1}2] or for indexes higher than 9 as in [^\g{1234}]]]
  125. [[[^\g-1]][Match whatever matched the last opened sub-expression]]
  126. [[[^\g{-2}]][Match whatever matched the last but one opened sub-expression]]
  127. [[[^\g{one}]][Match whatever matched the sub-expression named "one"]]
  128. ]
  129. Finally the \k escape can be used to refer to named subexpressions, for example [^\k<two>] will match
  130. whatever matched the subexpression named "two".
  131. [h4 Alternation]
  132. The [^|] operator will match either of its arguments, so for example:
  133. [^abc|def] will match either "abc" or "def".
  134. Parenthesis can be used to group alternations, for example: [^ab(d|ef)]
  135. will match either of "abd" or "abef".
  136. Empty alternatives are not allowed (these are almost always a mistake), but
  137. if you really want an empty alternative use [^(?:)] as a placeholder, for example:
  138. [^|abc] is not a valid expression, but
  139. [^(?:)|abc] is and is equivalent, also the expression:
  140. [^(?:abc)??] has exactly the same effect.
  141. [h4 Character sets]
  142. A character set is a bracket-expression starting with [^[] and ending with [^]],
  143. it defines a set of characters, and matches any single character that is a
  144. member of that set.
  145. A bracket expression may contain any combination of the following:
  146. [h5 Single characters]
  147. For example [^\[abc\]], will match any of the characters 'a', 'b', or 'c'.
  148. [h5 Character ranges]
  149. For example [^\[a-c\]] will match any single character in the range 'a' to 'c'.
  150. By default, for Perl regular expressions, a character x is within the
  151. range y to z, if the code point of the character lies within the codepoints of
  152. the endpoints of the range. Alternatively, if you set the
  153. [link boost_regex.ref.syntax_option_type.syntax_option_type_perl [^collate] flag]
  154. when constructing the regular expression, then ranges are locale sensitive.
  155. [h5 Negation]
  156. If the bracket-expression begins with the ^ character, then it matches the
  157. complement of the characters it contains, for example [^\[^a-c\]] matches
  158. any character that is not in the range [^a-c].
  159. [h5 Character classes]
  160. An expression of the form [^\[\[:name:\]\]] matches the named character class
  161. "name", for example [^\[\[:lower:\]\]] matches any lower case character.
  162. See [link boost_regex.syntax.character_classes character class names].
  163. [h5 Collating Elements]
  164. An expression of the form [^\[\[.col.\]\]] matches the collating element /col/.
  165. A collating element is any single character, or any sequence of characters
  166. that collates as a single unit. Collating elements may also be used
  167. as the end point of a range, for example: [^\[\[.ae.\]-c\]] matches the
  168. character sequence "ae", plus any single character in the range "ae"-c,
  169. assuming that "ae" is treated as a single collating element in the current locale.
  170. As an extension, a collating element may also be specified via it's
  171. [link boost_regex.syntax.collating_names symbolic name], for example:
  172. [[.NUL.]]
  173. matches a [^\0] character.
  174. [h5 Equivalence classes]
  175. An expression of the form [^\[\[\=col\=\]\]], matches any character or collating element
  176. whose primary sort key is the same as that for collating element /col/, as with
  177. collating elements the name /col/ may be a
  178. [link boost_regex.syntax.collating_names symbolic name]. A primary sort key is
  179. one that ignores case, accentation, or locale-specific tailorings; so for
  180. example `[[=a=]]` matches any of the characters:
  181. a, '''&#xC0;''', '''&#xC1;''', '''&#xC2;''',
  182. '''&#xC3;''', '''&#xC4;''', '''&#xC5;''', A, '''&#xE0;''', '''&#xE1;''',
  183. '''&#xE2;''', '''&#xE3;''', '''&#xE4;''' and '''&#xE5;'''.
  184. Unfortunately implementation of this is reliant on the platform's collation
  185. and localisation support; this feature can not be relied upon to work portably
  186. across all platforms, or even all locales on one platform.
  187. [h5 Escaped Characters]
  188. All the escape sequences that match a single character, or a single character
  189. class are permitted within a character class definition. For example
  190. `[\[\]]` would match either of `[` or `]` while `[\W\d]` would match any character
  191. that is either a "digit", /or/ is /not/ a "word" character.
  192. [h5 Combinations]
  193. All of the above can be combined in one character set declaration, for example:
  194. [^\[\[:digit:\]a-c\[.NUL.\]\]].
  195. [h4 Escapes]
  196. Any special character preceded by an escape shall match itself.
  197. The following escape sequences are all synonyms for single characters:
  198. [table
  199. [[Escape][Character]]
  200. [[[^\\a]][[^\\a]]]
  201. [[[^\\e]][[^0x1B]]]
  202. [[[^\\f]][[^\\f]]]
  203. [[[^\\n]][[^\\n]]]
  204. [[[^\\r]][[^\\r]]]
  205. [[[^\\t]][[^\\t]]]
  206. [[[^\\v]][[^\\v]]]
  207. [[[^\\b]][[^\\b] (but only inside a character class declaration).]]
  208. [[[^\\cX]][An ASCII escape sequence - the character whose code point is X % 32]]
  209. [[[^\\xdd]][A hexadecimal escape sequence - matches the single character whose
  210. code point is 0xdd.]]
  211. [[[^\\x{dddd}]][A hexadecimal escape sequence - matches the single character whose
  212. code point is 0xdddd.]]
  213. [[[^\\0ddd]][An octal escape sequence - matches the single character whose
  214. code point is 0ddd.]]
  215. [[[^\\N{name}]][Matches the single character which has the
  216. [link boost_regex.syntax.collating_names symbolic name] /name/.
  217. For example [^\\N{newline}] matches the single character \\n.]]
  218. ]
  219. [h5 "Single character" character classes:]
  220. Any escaped character /x/, if /x/ is the name of a character class shall
  221. match any character that is a member of that class, and any
  222. escaped character /X/, if /x/ is the name of a character class, shall
  223. match any character not in that class.
  224. The following are supported by default:
  225. [table
  226. [[Escape sequence][Equivalent to]]
  227. [[`\d`][`[[:digit:]]`]]
  228. [[`\l`][`[[:lower:]]`]]
  229. [[`\s`][`[[:space:]]`]]
  230. [[`\u`][`[[:upper:]]`]]
  231. [[`\w`][`[[:word:]]`]]
  232. [[`\h`][Horizontal whitespace]]
  233. [[`\v`][Vertical whitespace]]
  234. [[`\D`][`[^[:digit:]]`]]
  235. [[`\L`][`[^[:lower:]]`]]
  236. [[`\S`][`[^[:space:]]`]]
  237. [[`\U`][`[^[:upper:]]`]]
  238. [[`\W`][`[^[:word:]]`]]
  239. [[`\H`][Not Horizontal whitespace]]
  240. [[`\V`][Not Vertical whitespace]]
  241. ]
  242. [h5 Character Properties]
  243. The character property names in the following table are all equivalent
  244. to the [link boost_regex.syntax.character_classes names used in character classes].
  245. [table
  246. [[Form][Description][Equivalent character set form]]
  247. [[`\pX`][Matches any character that has the property X.][`[[:X:]]`]]
  248. [[`\p{Name}`][Matches any character that has the property Name.][`[[:Name:]]`]]
  249. [[`\PX`][Matches any character that does not have the property X.][`[^[:X:]]`]]
  250. [[`\P{Name}`][Matches any character that does not have the property Name.][`[^[:Name:]]`]]
  251. ]
  252. For example [^\pd] matches any "digit" character, as does [^\p{digit}].
  253. [h5 Word Boundaries]
  254. The following escape sequences match the boundaries of words:
  255. [^\<] Matches the start of a word.
  256. [^\>] Matches the end of a word.
  257. [^\b] Matches a word boundary (the start or end of a word).
  258. [^\B] Matches only when not at a word boundary.
  259. [h5 Buffer boundaries]
  260. The following match only at buffer boundaries: a "buffer" in this
  261. context is the whole of the input text that is being matched against
  262. (note that ^ and $ may match embedded newlines within the text).
  263. \\\` Matches at the start of a buffer only.
  264. \\' Matches at the end of a buffer only.
  265. \\A Matches at the start of a buffer only (the same as [^\\\`]).
  266. \\z Matches at the end of a buffer only (the same as [^\\']).
  267. \\Z Matches a zero-width assertion consisting of an optional sequence of newlines at the end of a buffer:
  268. equivalent to the regular expression [^(?=\\v*\\z)]. Note that this is subtly different from Perl which
  269. behaves as if matching [^(?=\\n?\\z)].
  270. [h5 Continuation Escape]
  271. The sequence [^\G] matches only at the end of the last match found, or at
  272. the start of the text being matched if no previous match was found.
  273. This escape useful if you're iterating over the matches contained within a
  274. text, and you want each subsequence match to start where the last one ended.
  275. [h5 Quoting escape]
  276. The escape sequence [^\Q] begins a "quoted sequence": all the subsequent characters
  277. are treated as literals, until either the end of the regular expression or \\E
  278. is found. For example the expression: [^\Q\*+\Ea+] would match either of:
  279. \*+a
  280. \*+aaa
  281. [h5 Unicode escapes]
  282. [^\C] Matches a single code point: in Boost regex this has exactly the
  283. same effect as a "." operator.
  284. [^\X] Matches a combining character sequence: that is any non-combining
  285. character followed by a sequence of zero or more combining characters.
  286. [h5 Matching Line Endings]
  287. The escape sequence [^\R] matches any line ending character sequence, specifically it is identical to
  288. the expression [^(?>\x0D\x0A?|\[\x0A-\x0C\x85\x{2028}\x{2029}\])].
  289. [h5 Keeping back some text]
  290. [^\K] Resets the start location of $0 to the current text position: in other words everything to the
  291. left of \K is "kept back" and does not form part of the regular expression match. $` is updated
  292. accordingly.
  293. For example [^foo\Kbar] matched against the text "foobar" would return the match "bar" for $0 and "foo"
  294. for $`. This can be used to simulate variable width lookbehind assertions.
  295. [h5 Any other escape]
  296. Any other escape sequence matches the character that is escaped, for example
  297. \\@ matches a literal '@'.
  298. [h4 Perl Extended Patterns]
  299. Perl-specific extensions to the regular expression syntax all start with [^(?].
  300. [h5 Named Subexpressions]
  301. You can create a named subexpression using:
  302. (?<NAME>expression)
  303. Which can be then be referred to by the name /NAME/. Alternatively you can delimit the name
  304. using 'NAME' as in:
  305. (?'NAME'expression)
  306. These named subexpressions can be referred to in a backreference using either [^\g{NAME}] or [^\k<NAME>]
  307. and can also be referred to by name in a [perl_format] format string for search and replace operations, or in the
  308. [match_results] member functions.
  309. [h5 Comments]
  310. [^(?# ... )] is treated as a comment, it's contents are ignored.
  311. [h5 Modifiers]
  312. [^(?imsx-imsx ... )] alters which of the perl modifiers are in effect within
  313. the pattern, changes take effect from the point that the block is first seen
  314. and extend to any enclosing [^)]. Letters before a '-' turn that perl
  315. modifier on, letters afterward, turn it off.
  316. [^(?imsx-imsx:pattern)] applies the specified modifiers to pattern only.
  317. [h5 Non-marking groups]
  318. [^(?:pattern)] lexically groups pattern, without generating an additional
  319. sub-expression.
  320. [h5 Branch reset]
  321. [^(?|pattern)] resets the subexpression count at the start of each "|" alternative within /pattern/.
  322. The sub-expression count following this construct is that of whichever branch had the largest number of
  323. sub-expressions. This construct is useful when you want to capture one of a number of alternative matches
  324. in a single sub-expression index.
  325. In the following example the index of each sub-expression is shown below the expression:
  326. [pre
  327. # before ---------------branch-reset----------- after
  328. / ( a ) (?| x ( y ) z | (p (q) r) | (t) u (v) ) ( z ) /x
  329. # 1 2 2 3 2 3 4
  330. ]
  331. [h5 Lookahead]
  332. [^(?=pattern)] consumes zero characters, only if pattern matches.
  333. [^(?!pattern)] consumes zero characters, only if pattern does not match.
  334. Lookahead is typically used to create the logical AND of two regular
  335. expressions, for example if a password must contain a lower case letter,
  336. an upper case letter, a punctuation symbol, and be at least 6 characters long,
  337. then the expression:
  338. (?=.*[[:lower:]])(?=.*[[:upper:]])(?=.*[[:punct:]]).{6,}
  339. could be used to validate the password.
  340. [h5 Lookbehind]
  341. [^(?<=pattern)] consumes zero characters, only if pattern could be matched
  342. against the characters preceding the current position (pattern must be
  343. of fixed length).
  344. [^(?<!pattern)] consumes zero characters, only if pattern could not be
  345. matched against the characters preceding the current position (pattern must
  346. be of fixed length).
  347. [h5 Independent sub-expressions]
  348. [^(?>pattern)] /pattern/ is matched independently of the surrounding patterns,
  349. the expression will never backtrack into /pattern/. Independent sub-expressions
  350. are typically used to improve performance; only the best possible match
  351. for pattern will be considered, if this doesn't allow the expression as a
  352. whole to match then no match is found at all.
  353. [h5 Recursive Expressions]
  354. [^(?['N]) (?-['N]) (?+['N]) (?R) (?0) (?&NAME)]
  355. [^(?R)] and [^(?0)] recurse to the start of the entire pattern.
  356. [^(?['N])] executes sub-expression /N/ recursively, for example [^(?2)] will recurse to sub-expression 2.
  357. [^(?-['N])] and [^(?+['N])] are relative recursions, so for example [^(?-1)] recurses to the last sub-expression to be declared,
  358. and [^(?+1)] recurses to the next sub-expression to be declared.
  359. [^(?&NAME)] recurses to named sub-expression ['NAME].
  360. [h5 Conditional Expressions]
  361. [^(?(condition)yes-pattern|no-pattern)] attempts to match /yes-pattern/ if
  362. the /condition/ is true, otherwise attempts to match /no-pattern/.
  363. [^(?(condition)yes-pattern)] attempts to match /yes-pattern/ if the /condition/
  364. is true, otherwise matches the NULL string.
  365. /condition/ may be either: a forward lookahead assert, the index of
  366. a marked sub-expression (the condition becomes true if the sub-expression
  367. has been matched), or an index of a recursion (the condition become true if we are executing
  368. directly inside the specified recursion).
  369. Here is a summary of the possible predicates:
  370. * [^(?(?\=assert)yes-pattern|no-pattern)] Executes /yes-pattern/ if the forward look-ahead assert matches, otherwise
  371. executes /no-pattern/.
  372. * [^(?(?!assert)yes-pattern|no-pattern)] Executes /yes-pattern/ if the forward look-ahead assert does not match, otherwise
  373. executes /no-pattern/.
  374. * [^(?(['N])yes-pattern|no-pattern)] Executes /yes-pattern/ if subexpression /N/ has been matched, otherwise
  375. executes /no-pattern/.
  376. * [^(?(<['name]>)yes-pattern|no-pattern)] Executes /yes-pattern/ if named subexpression /name/ has been matched, otherwise
  377. executes /no-pattern/.
  378. * [^(?('['name]')yes-pattern|no-pattern)] Executes /yes-pattern/ if named subexpression /name/ has been matched, otherwise
  379. executes /no-pattern/.
  380. * [^(?(R)yes-pattern|no-pattern)] Executes /yes-pattern/ if we are executing inside a recursion, otherwise
  381. executes /no-pattern/.
  382. * [^(?(R['N])yes-pattern|no-pattern)] Executes /yes-pattern/ if we are executing inside a recursion to sub-expression /N/, otherwise
  383. executes /no-pattern/.
  384. * [^(?(R&['name])yes-pattern|no-pattern)] Executes /yes-pattern/ if we are executing inside a recursion to named sub-expression /name/, otherwise
  385. executes /no-pattern/.
  386. * [^(?(DEFINE)never-exectuted-pattern)] Defines a block of code that is never executed and matches no characters:
  387. this is usually used to define one or more named sub-expressions which are referred to from elsewhere in the pattern.
  388. [h5 Backtracking Control Verbs]
  389. This library has partial support for Perl's backtracking control verbs, in particular (*MARK) is not supported.
  390. There may also be detail differences in behaviour between this library and Perl, not least because Perl's behaviour
  391. is rather under-documented and often somewhat random in how it behaves in practice. The verbs supported are:
  392. * [^(*PRUNE)] Has no effect unless backtracked onto, in which case all the backtracking information prior to this
  393. point is discarded.
  394. * [^(*SKIP)] Behaves the same as [^(*PRUNE)] except that it is assumed that no match can possibly occur prior to
  395. the current point in the string being searched. This can be used to optimize searches by skipping over chunks of text
  396. that have already been determined can not form a match.
  397. * [^(*THEN)] Has no effect unless backtracked onto, in which case all subsequent alternatives in a group of alternations
  398. are discarded.
  399. * [^(*COMMIT)] Has no effect unless backtracked onto, in which case all subsequent matching/searching attempts are abandoned.
  400. * [^(*FAIL)] Causes the match to fail unconditionally at this point, can be used to force the engine to backtrack.
  401. * [^(*ACCEPT)] Causes the pattern to be considered matched at the current point. Any half-open sub-expressions are closed at the current point.
  402. [h4 Operator precedence]
  403. The order of precedence for of operators is as follows:
  404. # Collation-related bracket symbols `[==] [::] [..]`
  405. # Escaped characters [^\\]
  406. # Character set (bracket expression) `[]`
  407. # Grouping [^()]
  408. # Single-character-ERE duplication [^* + ? {m,n}]
  409. # Concatenation
  410. # Anchoring ^$
  411. # Alternation |
  412. [h3 What gets matched]
  413. If you view the regular expression as a directed (possibly cyclic)
  414. graph, then the best match found is the first match found by a
  415. depth-first-search performed on that graph, while matching the input text.
  416. Alternatively:
  417. The best match found is the
  418. [link boost_regex.syntax.leftmost_longest_rule leftmost match],
  419. with individual elements matched as follows;
  420. [table
  421. [[Construct][What gets matched]]
  422. [[[^AtomA AtomB]][Locates the best match for /AtomA/ that has a following match for /AtomB/.]]
  423. [[[^Expression1 | Expression2]][If /Expresion1/ can be matched then returns that match,
  424. otherwise attempts to match /Expression2/.]]
  425. [[[^S{N}]][Matches /S/ repeated exactly N times.]]
  426. [[[^S{N,M}]][Matches S repeated between N and M times, and as many times as possible.]]
  427. [[[^S{N,M}?]][Matches S repeated between N and M times, and as few times as possible.]]
  428. [[[^S?, S*, S+]][The same as [^S{0,1}], [^S{0,UINT_MAX}], [^S{1,UINT_MAX}] respectively.]]
  429. [[[^S??, S*?, S+?]][The same as [^S{0,1}?], [^S{0,UINT_MAX}?], [^S{1,UINT_MAX}?] respectively.]]
  430. [[[^(?>S)]][Matches the best match for /S/, and only that.]]
  431. [[[^(?=S), (?<=S)]][Matches only the best match for /S/ (this is only
  432. visible if there are capturing parenthesis within /S/).]]
  433. [[[^(?!S), (?<!S)]][Considers only whether a match for S exists or not.]]
  434. [[[^(?(condition)yes-pattern | no-pattern)]][If condition is true, then
  435. only yes-pattern is considered, otherwise only no-pattern is considered.]]
  436. ]
  437. [h3 Variations]
  438. The [link boost_regex.ref.syntax_option_type.syntax_option_type_perl options [^normal],
  439. [^ECMAScript], [^JavaScript] and [^JScript]] are all synonyms for
  440. [^perl].
  441. [h3 Options]
  442. There are a [link boost_regex.ref.syntax_option_type.syntax_option_type_perl
  443. variety of flags] that may be combined with the [^perl] option when
  444. constructing the regular expression, in particular note that the
  445. [^newline_alt] option alters the syntax, while the [^collate], [^nosubs] and
  446. [^icase] options modify how the case and locale sensitivity are to be applied.
  447. [h3 Pattern Modifiers]
  448. The perl [^smix] modifiers can either be applied using a [^(?smix-smix)]
  449. prefix to the regular expression, or with one of the
  450. [link boost_regex.ref.syntax_option_type.syntax_option_type_perl regex-compile time
  451. flags [^no_mod_m], [^mod_x], [^mod_s], and [^no_mod_s]].
  452. [h3 References]
  453. [@http://perldoc.perl.org/perlre.html Perl 5.8].
  454. [endsect]