std::regex_constants::syntax_option_type

Header: <regex>

  1. The syntax_option_type is a BitmaskType that contains options that govern how regular expressions behave.

# Declarations

using syntax_option_type = /* implementation-defined */;

(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) (inline since C++17)

inline constexpr syntax_option_type multiline = /* unspecified */;

(since C++17)

# Notes

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[^>]>.” would match everything from the first “<tag” to the last “”, including every “” and “” in-between. On the other hand, ECMAScript supports non-greedy matches, and the ECMAScript regex “<tag[^>]>.?” would match only until the first closing tag.

# Example

#include <iostream>
#include <regex>
#include <string>
 
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';
}

# Defect reports

DRApplied toBehavior as publishedCorrect behavior
LWG 2053C++11the constants were declared staticremoved the static specifier

# See also