syntax_perl.qbk
来自「Boost provides free peer-reviewed portab」· QBK 代码 · 共 517 行 · 第 1/2 页
QBK
517 行
[table[[Escape][Character]][[`\a`][`\a`]][[`\e`][`0x1B`]][[`\f`][`\f`]][[`\n`][`\n`]][[`\r`][`\r`]][[`\t`][`\t`]][[`\v `][`\v`]][[`\b`][`\b` (but only inside a character class declaration).]][[`\cX`][An ASCII escape sequence - the character whose code point is X % 32]][[`\xdd`][A hexadecimal escape sequence - matches the single character whose code point is 0xdd.]][[`\x{dddd}`][A hexadecimal escape sequence - matches the single character whose code point is 0xdddd.]][[`\0ddd`][An octal escape sequence - matches the single character whose code point is 0ddd.]][[`\N{name}`][Matches the single character which has the [link boost_regex.syntax.collating_names symbolic name] /name/. For example `\N{newline}` matches the single character \\n.]]] [h5 "Single character" character classes:]Any escaped character /x/, if /x/ is the name of a character class shall match any character that is a member of that class, and any escaped character /X/, if /x/ is the name of a character class, shall match any character not in that class.The following are supported by default:[table[[Escape sequence][Equivalent to]][[`\d`][`[[:digit:]]`]][[`\l`][`[[:lower:]]`]][[`\s`][`[[:space:]]`]][[`\u`][`[[:upper:]]`]][[`\w`][`[[:word:]]`]][[`\D`][`[^[:digit:]]`]][[`\L`][`[^[:lower:]]`]][[`\S`][`[^[:space:]]`]][[`\U`][`[^[:upper:]]`]][[`\W`][`[^[:word:]]`]]][h5 Character Properties]The character property names in the following table are all equivalent to the [link boost_regex.syntax.character_classes names used in character classes].[table[[Form][Description][Equivalent character set form]][[`\pX`][Matches any character that has the property X.][`[[:X:]]`]][[`\p{Name}`][Matches any character that has the property Name.][`[[:Name:]]`]][[`\PX`][Matches any character that does not have the property X.][`[^[:X:]]`]][[`\P{Name}`][Matches any character that does not have the property Name.][`[^[:Name:]]`]]]For example `\pd` matches any "digit" character, as does `\p{digit}`.[h5 Word Boundaries]The following escape sequences match the boundaries of words:`\<` Matches the start of a word.`\>` Matches the end of a word.`\b` Matches a word boundary (the start or end of a word).`\B` Matches only when not at a word boundary.[h5 Buffer boundaries]The following match only at buffer boundaries: a "buffer" in this context is the whole of the input text that is being matched against (note that ^ and $ may match embedded newlines within the text).\\\` Matches at the start of a buffer only.\\' Matches at the end of a buffer only.\\A Matches at the start of a buffer only (the same as \\\`).\\z Matches at the end of a buffer only (the same as \\').\\Z Matches an optional sequence of newlines at the end of a buffer: equivalent to the regular expression `\n*\z`[h5 Continuation Escape]The sequence `\G` matches only at the end of the last match found, or at the start of the text being matched if no previous match was found. This escape useful if you're iterating over the matches contained within a text, and you want each subsequence match to start where the last one ended.[h5 Quoting escape]The escape sequence `\Q` begins a "quoted sequence": all the subsequent characters are treated as literals, until either the end of the regular expression or \\E is found. For example the expression: `\Q\*+\Ea+` would match either of: \*+a \*+aaa[h5 Unicode escapes]`\C` Matches a single code point: in Boost regex this has exactly the same effect as a "." operator.`\X` Matches a combining character sequence: that is any non-combining character followed by a sequence of zero or more combining characters. [h5 Any other escape]Any other escape sequence matches the character that is escaped, for example \\@ matches a literal '@'.[h4 Perl Extended Patterns]Perl-specific extensions to the regular expression syntax all start with `(?`.[h5 Comments]`(?# ... )` is treated as a comment, it's contents are ignored.[h5 Modifiers]`(?imsx-imsx ... )` alters which of the perl modifiers are in effect within the pattern, changes take effect from the point that the block is first seen and extend to any enclosing `)`. Letters before a '-' turn that perl modifier on, letters afterward, turn it off.`(?imsx-imsx:pattern)` applies the specified modifiers to pattern only.[h5 Non-marking groups]`(?:pattern)` lexically groups pattern, without generating an additional sub-expression.[h5 Lookahead]`(?=pattern)` consumes zero characters, only if pattern matches.`(?!pattern)` consumes zero characters, only if pattern does not match.Lookahead is typically used to create the logical AND of two regular expressions, for example if a password must contain a lower case letter, an upper case letter, a punctuation symbol, and be at least 6 characters long, then the expression: (?=.*[[:lower:]])(?=.*[[:upper:]])(?=.*[[:punct:]]).{6,}could be used to validate the password.[h5 Lookbehind]`(?<=pattern)` consumes zero characters, only if pattern could be matched against the characters preceding the current position (pattern must be of fixed length).`(?<!pattern)` consumes zero characters, only if pattern could not be matched against the characters preceding the current position (pattern must be of fixed length).[h5 Independent sub-expressions]`(?>pattern)` /pattern/ is matched independently of the surrounding patterns, the expression will never backtrack into /pattern/. Independent sub-expressions are typically used to improve performance; only the best possible match for pattern will be considered, if this doesn't allow the expression as a whole to match then no match is found at all.[h5 Conditional Expressions]`(?(condition)yes-pattern|no-pattern)` attempts to match /yes-pattern/ if the /condition/ is true, otherwise attempts to match /no-pattern/.`(?(condition)yes-pattern)` attempts to match /yes-pattern/ if the /condition/ is true, otherwise fails./condition/ may be either a forward lookahead assert, or the index of a marked sub-expression (the condition becomes true if the sub-expression has been matched).[h4 Operator precedence]The order of precedence for of operators is as follows:# Collation-related bracket symbols `[==] [::] [..]`# Escaped characters `\`# Character set (bracket expression) `[]`# Grouping `()`# Single-character-ERE duplication `* + ? {m,n}`# Concatenation # Anchoring ^$# Alternation |[h3 What gets matched]If you view the regular expression as a directed (possibly cyclic) graph, then the best match found is the first match found by a depth-first-search performed on that graph, while matching the input text.Alternatively:The best match found is the [link boost_regex.syntax.leftmost_longest_rule leftmost match], with individual elements matched as follows;[table[[Construct][What gets matched]][[`AtomA AtomB`][Locates the best match for /AtomA/ that has a following match for /AtomB/.]][[`Expression1 | Expression2`][If /Expresion1/ can be matched then returns that match, otherwise attempts to match /Expression2/.]][[`S{N}`][Matches /S/ repeated exactly N times.]][[`S{N,M}`][Matches S repeated between N and M times, and as many times as possible.]][[`S{N,M}?`][Matches S repeated between N and M times, and as few times as possible.]][[`S?, S*, S+`][The same as `S{0,1}`, `S{0,UINT_MAX}`, `S{1,UINT_MAX}` respectively.]][[`S??, S*?, S+?`][The same as `S{0,1}?`, `S{0,UINT_MAX}?`, `S{1,UINT_MAX}?` respectively.]][[`(?>S)`][Matches the best match for /S/, and only that.]][[`(?=S), (?<=S)`][Matches only the best match for /S/ (this is only visible if there are capturing parenthesis within /S/).]][[`(?!S), (?<!S)`][Considers only whether a match for S exists or not.]][[`(?(condition)yes-pattern | no-pattern)`][If condition is true, then only yes-pattern is considered, otherwise only no-pattern is considered.]]][h3 Variations]The [link boost_regex.ref.syntax_option_type.syntax_option_type_perl options `normal`, `ECMAScript`, `JavaScript` and `JScript`] are all synonyms for `perl`.[h3 Options]There are a [link boost_regex.ref.syntax_option_type.syntax_option_type_perl variety of flags] that may be combined with the `perl` option when constructing the regular expression, in particular note that the `newline_alt` option alters the syntax, while the `collate`, `nosubs` and `icase` options modify how the case and locale sensitivity are to be applied.[h3 Pattern Modifiers]The perl `smix` modifiers can either be applied using a `(?smix-smix)` prefix to the regular expression, or with one of the [link boost_regex.ref.syntax_option_type.syntax_option_type_perl regex-compile time flags `no_mod_m`, `mod_x`, `mod_s`, and `no_mod_s`].[h3 References][@http://perldoc.perl.org/perlre.html Perl 5.8].[endsect]
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?