std::regex_constants::syntax_option_type
STD::regex[医]常量::语法[医]期权[医]类型
Defined in header | | |
---|---|---|
typedef /*unspecified*/ syntax_option_type; | | (since C++11) |
constexpr syntax_option_type icase = /*unspecified*/; constexpr syntax_option_type nosubs = /*unspecified*/; constexpr syntax_option_type optimize = /*unspecified*/; constexpr syntax_option_type collate = /*unspecified*/; constexpr syntax_option_type ECMAScript = /*unspecified*/; constexpr syntax_option_type basic = /*unspecified*/; constexpr syntax_option_type extended = /*unspecified*/; constexpr syntax_option_type awk = /*unspecified*/; constexpr syntax_option_type grep = /*unspecified*/; constexpr syntax_option_type egrep = /*unspecified*/; | | (since C++11) (until C++17) |
inline constexpr syntax_option_type icase = /*unspecified*/; inline constexpr syntax_option_type nosubs = /*unspecified*/; inline constexpr syntax_option_type optimize = /*unspecified*/; inline constexpr syntax_option_type collate = /*unspecified*/; inline constexpr syntax_option_type ECMAScript = /*unspecified*/; inline constexpr syntax_option_type basic = /*unspecified*/; inline constexpr syntax_option_type extended = /*unspecified*/; inline constexpr syntax_option_type awk = /*unspecified*/; inline constexpr syntax_option_type grep = /*unspecified*/; inline constexpr syntax_option_type egrep = /*unspecified*/; inline constexpr syntax_option_type multiline = /*unspecified*/; | | (since C++17) |
大syntax_option_type
是BitmaskType
它包含控制正则表达式行为的选项。
此类型%28的可能值icase
,,,optimize
,等%29在内部复制性病:基本[医]雷吉...
常数
Value | Effect(s) |
---|---|
icase | Character matching should be performed without regard to case. |
nosubs | When performing matches, all marked sub-expressions (expr) are treated as non-marking sub-expressions (?:expr). No matches are stored in the supplied std::regex_match structure and mark_count() is zero |
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. |
multiline (C++17) | Specifies that ^ shall match the beginning of a line and $ shall match the end of a line, if the ECMAScript engine is selected. |
ECMAScript | Use the Modified ECMAScript regular expression grammar |
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 '|'. |
最多只能选择一个语法选项。ECMAScript
,,,basic
,,,extended
,,,awk
,,,grep
,,,egrep
如果没有选择语法,ECMAScript
被假定是被选中的。其他选项用作修饰符,例如std::regex
("meow", std::regex::icase)
等于std::regex
("meow", std::regex::ECMAScript|std::regex::icase)
...
注记
由于POSIX使用“最左边最长”匹配规则%28,因此匹配最长的匹配子序列,如果有几个这样的子序列,则二匹配%29,因此不适合例如解析标记语言:POSIX正则表达式,例如"<tag[^>]*>.*</tag>"从第一次"<tag"直到最后"</tag>",包括每一个"</tag>"和"<tag>"中间。另一方面,ecmaScript支持非贪婪的匹配,ecmaScript正则表达式。"<tag[^>]*>.*?</tag>"只会在第一个结束标记之前匹配。
在C++11中,这些常量是用冗余关键字指定的。static
,它被C++14通过lwg第2053期...
例
说明ECMAScript和POSIX正则表达式在匹配算法上的区别。
二次
#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
二次
另见
basic_regex (C++11) | regular expression object (class template) |
---|
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。