42 static std::string error_string(
const std::regex_error& err)
46 case std::regex_constants::error_collate :
47 return "invalid collating element name";
50 case std::regex_constants::error_ctype :
51 return "invalid character class name";
54 case std::regex_constants::error_escape :
55 return "invalid escaped character or a trailing escape";
58 case std::regex_constants::error_backref :
59 return "invalid back reference";
62 case std::regex_constants::error_brack :
63 return "mismatched [ and ]";
66 case std::regex_constants::error_paren :
67 return "mismatched ( and )";
70 case std::regex_constants::error_brace :
71 return "mismatched { and }";
74 case std::regex_constants::error_badbrace :
75 return "invalid range in a {..}";
78 case std::regex_constants::error_range :
79 return "invalid [..] character range";
82 case std::regex_constants::error_space :
83 return "memory error";
86 case std::regex_constants::error_badrepeat :
87 return "bad '*?+{' repeat";
90 case std::regex_constants::error_complexity :
91 return "expression too complex";
94 case std::regex_constants::error_stack :
95 return "memory stack error";
115 size_t len = (pattern ? strlen(pattern) : 0);
123 std::regex::flag_type flags = syntax();
126 flags |= std::regex::icase;
129 const char* pat = pattern;
132 if (len >= 4 && !strncmp(pattern,
"(?i)", 4))
134 flags |= std::regex::icase;
143 re_.assign(pat, flags);
146 catch (
const std::regex_error& err)
149 <<
"Failed to compile regular expression '"
150 << pattern <<
"'" <<
nl
151 << err.what() <<
": " << error_string(err).c_str() <<
nl
164 auto len = pattern.size();
172 std::regex::flag_type flags = syntax();
175 flags |= std::regex::icase;
178 auto pat = pattern.begin();
181 if (len >= 4 && !pattern.compare(0, 4,
"(?i)"))
183 flags |= std::regex::icase;
192 re_.assign(pat, pattern.end(), flags);
195 catch (
const std::regex_error& err)
198 <<
"Failed to compile regular expression '"
199 << pattern.c_str() <<
"'" <<
nl
200 << err.what() <<
": " << error_string(err).c_str() <<
nl