std::regex_constants::syntax_option_type
来自cppreference.com
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
在头文件 <regex> 中定义
|
||
typedef /*unspecified*/ syntax_option_type; static constexpr syntax_option_type icase = /*unspecified*/; |
||
syntax_option_type
是一个BitmaskType
包含的选项,如何正则表达式的行为.原文:
The
syntax_option_type
is a BitmaskType
that contains options that govern how regular expressions behave.对于此类型的可能的值(
icase
,optimize
等)内被复制的std :: basic_regex.原文:
The possible values for this type (
icase
, optimize
, etc.) are duplicated inside 的std :: basic_regex.目录 |
[编辑] 常量
值
|
Effect(s) |
icase
|
Character matching should be performed without regard to case. |
nosubs
|
When performing matches, no sub-expression matches should be stored in the supplied std::regex_match structure. |
optimize
|
Instructs the regular expression engine to make matching faster, with the potential cost of making construction slower. For example, this might mean converting a non-deterministic FSA to a deterministic FSA. |
collate
|
Character ranges of the form "[a-b]" will be locale sensitive. |
ECMAScript
|
Use the ECMAScript (JavaScript) regular expression grammar (ECMA-262 grammar documentation), modified to support collating elements, character classes, and equivalence classes from POSIX, and the character class aliases \d, \D, \s, \S, \w, and \W are made locale-sensitive |
basic
|
Use the basic POSIX regular expression grammar (grammar documentation). |
extended
|
Use the extended POSIX regular expression grammar (grammar documentation). |
awk
|
Use the regular expression grammar used by the awk utility in POSIX (grammar documentation) |
grep
|
Use the regular expression grammar used by the grep utility in POSIX. This is effectively the same as the basic option with the addition of newline '\n' as an alternation separator.
|
egrep
|
Use the regular expression grammar used by the grep utility, with the -E option, in POSIX. This is effectively the same as the extended option with the addition of newline '\n' as an alternation separator in addtion to '|'.
|
[编辑] 注释
因为POSIX使用“最左边的最长的”匹配规则(最长匹配的子序列是匹配的,并且,如果有多个这样的子序列,相匹配的第一个),它是不适合的,例如,用于解析标记语言:POSIX正则表达式如"<tag[^>]*>.*</tag>"将匹配一切从第一"<tag"到最后"</tag>",,包括每"</tag>"和"<tag>"之间。另一方面,ECMAScript支持非贪婪匹配,,在ECMAScript正则表达式"<tag[^>]*>.*?</tag>",直到第一个关闭标签将只匹配.
原文:
Because POSIX uses "leftmost longest" matching rule (the longest matching subsequence is matched, and if there are several such subsequences, the first one is matched), it is not suitable, for example, for parsing markup languages: a POSIX regex such as "<tag[^>]*>.*</tag>" would match everything from the first "<tag" to the last "</tag>", including every "</tag>" and "<tag>" inbetween. On the other hand, ECMAScript supports non-greedy matches, and the ECMAScript regex "<tag[^>]*>.*?</tag>" would match only until the first closing tag.
[编辑] 示例
说明ECMAScript和POSIX正则表达式匹配算法之间的差异
原文:
Illustrates the difference in the matching algorithm between ECMAScript and POSIX regular expressions
#include <iostream> #include <string> #include <regex> int main() { std::string str = "zzxayyzz"; std::regex re1(".*(a|xayy)"); // ECMA std::regex re2(".*(a|xayy)", std::regex::extended); // POSIX std::cout << "Searching for .*(a|xayy) in zzxayyzz:\n"; std::smatch m; std::regex_search(str, m, re1); std::cout << " ECMA (depth first search) match: " << m[0] << '\n'; std::regex_search(str, m, re2); std::cout << " POSIX (leftmost longest) match: " << m[0] << '\n'; }
输出:
Searching for .*(a|xayy) in zzxayyzz: ECMA (depth first search) match: zzxa POSIX (leftmost longest) match: zzxayy
[编辑] 另请参阅
(C++11) |
正则表达式对象 (类模板) |