std::regex_...:error_type(3)
π std::regex_constants::error_type π
okay so this page is std::regex_...:error_type(3) from the C++ Standard Libary manual, and bestie, it is literally the whole lore on std::regex_constants::error_type. no cap, itβs giving βtiny type, big error-energy.β π«Ά
β¨ NAME β¨
std::regex_constants::error_typeβ and the description is literally juststd::regex_constants::error_typeagain. iconic repetition, no notes. π
πΈ Synopsis πΈ
okay so hereβs the synopsis, and yes itβs a whole parade of /* unspecified */ constants. letβs go:
Defined in header <regex>
using error_type = /* implementation-defined */; (1) (since C++11)
constexpr error_type error_collate = /* unspecified */;
constexpr error_type error_ctype = /* unspecified */;
constexpr error_type error_escape = /* unspecified */;
constexpr error_type error_backref = /* unspecified */;
constexpr error_type error_brack = /* unspecified */;
constexpr error_type error_paren = /* unspecified */;
constexpr error_type error_brace = /* unspecified */; (since C++11)
(until C++17)
constexpr error_type error_badbrace = /* unspecified */;
constexpr error_type error_range = /* unspecified */;
constexpr error_type error_space = /* unspecified */;
constexpr error_type error_badrepeat = /* unspecified */;
constexpr error_type error_complexity = /* unspecified */;
constexpr error_type error_stack = /* unspecified */; (2)
inline constexpr error_type error_collate = /* unspecified */;
inline constexpr error_type error_ctype = /* unspecified */;
inline constexpr error_type error_escape = /* unspecified */;
inline constexpr error_type error_backref = /* unspecified */;
inline constexpr error_type error_brack = /* unspecified */;
inline constexpr error_type error_paren = /* unspecified */;
inline constexpr error_type error_brace = /* unspecified */; (since C++17)
inline constexpr error_type error_badbrace = /* unspecified */;
inline constexpr error_type error_range = /* unspecified */;
inline constexpr error_type error_space = /* unspecified */;
inline constexpr error_type error_badrepeat = /* unspecified */;
inline constexpr error_type error_complexity = /* unspecified */;
inline constexpr error_type error_stack = /* unspecified */;
- The
error_typeis a type that describes errors that may occur during regular expression parsing.
π Constants π
error_collateβ the expression contains an invalid collating element name. πerror_ctypeβ the expression contains an invalid character class name.error_escapeβ the expression contains an invalid escaped character or a trailing escape.error_backrefβ the expression contains an invalid back reference.error_brackβ the expression contains mismatched square brackets ('['and']').error_parenβ the expression contains mismatched parentheses ('('and')').error_braceβ the expression contains mismatched curly braces ('{'and'}').error_badbraceβ the expression contains an invalid range in a{}expression.error_rangeβ the expression contains an invalid character range (e.g.[b-a]).error_spaceβ there was not enough memory to convert the expression into a finite state machine.error_badrepeatβ'*','?','+'or'{'was not preceded by a valid regular expression.error_complexityβ the complexity of an attempted match exceeded a predefined level.error_stackβ there was not enough memory to perform a match.
π§ Example π§
Implements regular expressions checker:
// Run this code
#include <cstddef>
#include <iomanip>
#include <iostream>
#include <regex>
#include <sstream>
#include <string>
void regular_expression_checker(const std::string& text,
const std::string& regex,
const std::regex::flag_type flags)
{
std::cout << "Text: " << std::quoted(text) << '\n'
<< "Regex: " << std::quoted(regex) << '\n';
try
{
const std::regex re{regex, flags};
const bool matched = std::regex_match(text, re);
std::stringstream out;
out << (matched ? "MATCH!\n" : "DOES NOT MATCH!\n");
std::smatch m;
if (std::regex_search(text, m, re); !m.empty())
{
out << "prefix = [" << m.prefix().str().data() << "]\n";
for (std::size_t i{}; i != m.size(); ++i)
out << " m[" << i << "] = [" << m[i].str().data() << "]\n";
out << "suffix = [" << m.suffix().str().data() << "]\n";
}
std::cout << out.str() << '\n';
}
catch (std::regex_error& e)
{
std::cout << "Error: " << e.what() << ".\n\n";
}
}
int main()
{
constexpr std::regex::flag_type your_flags
= std::regex::flag_type{0}
// Choose one of the supported grammars:
| std::regex::ECMAScript
// | std::regex::basic
// | std::regex::extended
// | std::regex::awk
// | std::regex::grep
// | std::regex::egrep
// Choose any of the next options:
// | std::regex::icase
// | std::regex::nosubs
// | std::regex::optimize
// | std::regex::collate
// | std::regex::multiline
;
const std::string your_text = "Hello regular expressions.";
const std::string your_regex = R"(([a-zA-Z]+) ([a-z]+) ([a-z]+)\.)";
regular_expression_checker(your_text, your_regex, your_flags);
regular_expression_checker("Invalid!", R"(((.)(.))", your_flags);
regular_expression_checker("Invalid!", R"([.)", your_flags);
regular_expression_checker("Invalid!", R"([.]{})", your_flags);
regular_expression_checker("Invalid!", R"([1-0])", your_flags);
}
Possible output:
Text: "Hello regular expressions."
Regex: "([a-zA-Z]+) ([a-z]+) ([a-z]+)\\."
MATCH!
prefix = []
m[0] = [Hello regular expressions.]
m[1] = [Hello]
m[2] = [regular]
m[3] = [expressions]
suffix = []
Text: "Invalid!"
Regex: "((.)(.)"
Error: Mismatched '(' and ')' in regular expression.
Text: "Invalid!"
Regex: "[."
Error: Unexpected character within '[...]' in regular expression.
Text: "Invalid!"
Regex: "[.]{}"
Error: Invalid range in '{}' in regular expression.
Text: "Invalid!"
Regex: "[1-0]"
Error: Invalid range in bracket expression..
π₯ Defect reports π₯
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
- LWG 2053 β applied to C++11. Behavior as published: the constants were declared
static. Correct behavior: removed thestaticspecifier.
π¦ See also π¦
regex_errorβ reports errors generated by the regular expressions library. Itβs a class, and itβs marked C++11.
mwah π source: http://cppreference.com, version/date: 2024.06.10, page: std::regex_...:error_type(3) β thatβs the footer, bestie. π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms