[ Web Proxy ]
URL:
Viewing: https://ru.cppreference.com/cpp/regex/syntax_option_type [Back]  [Original]

std::regex_constants::syntax_option_type cppreference.com
cppreference.com

std::regex_constants::syntax_option_type

cppreference.com

<metanoindex/>

 
C++
(C++20)
(C++20)
(C++11)
(C++20)
/
(C++11)
(C++11)
(C++11)
(C++17)
 
 
<tbody> </tbody>
typedef /*unspecified*/ syntax_option_type; static constexpr syntax_option_type icase = /*unspecified*/; static constexpr syntax_option_type nosubs = /*unspecified*/; static constexpr syntax_option_type optimize = /*unspecified*/; static constexpr syntax_option_type collate = /*unspecified*/; static constexpr syntax_option_type ECMAScript = /*unspecified*/; static constexpr syntax_option_type basic = /*unspecified*/; static constexpr syntax_option_type extended = /*unspecified*/; static constexpr syntax_option_type awk = /*unspecified*/; static constexpr syntax_option_type grep = /*unspecified*/; static constexpr syntax_option_type egrep = /*unspecified*/;
syntax_option_type BitmaskType, , , .
:
The syntax_option_type is a BitmaskType that contains options that govern how regular expressions behave.
Google.
. .
(icase, optimize ..) std::basic_regex.
:
The possible values for this type (icase, optimize, etc.) are duplicated inside std::basic_regex.
Google.
. .

()
icase .
nosubs (expr) (?:expr). std::regex_match , mark_count() .
optimize . , FSA FSA.
collate "[a-b]" .
multiline (C++17) , ^ , $ , ECMAScript.
ECMAScript ECMAScript
basic POSIX ( ).
extended POSIX ( ).
awk , awk POSIX ( )
grep , grep POSIX. , basic '\n' .
egrep , grep POSIX -E. , extended '\n' '|'.

ECMAScript, basic, extended, awk, grep, egrep. , , ECMAScript. , std::regex("meow", std::regex::icase) std::regex("meow", std::regex::ECMAScript|std::regex::icase)

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.
Google.
. .

ECMAScript POSIX
:
Illustrates the difference in the matching algorithm between ECMAScript and POSIX regular expressions
Google.
. .

#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

.


( ) []

Web Proxy Viewer  |  New URL  |  Original Page