C ++中的regex_error
regex库具有与正则表达式相关的不同方法和功能。在这里,我们将看到一些regex_errors。这些也存在于正则表达式库中。在执行一些正则表达式期间,我们会遇到一些错误。这些错误在这里提到。
示例
#include <iostream>
#include <regex>
int main() {
try {
std::regex re("[A-Z][0"); //an error is present
} catch (const std::regex_error& err) {
std::cout << "There is an error. The error is: " << err.what() << '\n';
if (err.code() == std::regex_constants::error_brack) {
std::cout << "This is the code of error_brack\n";
}
}
}输出结果
There is an error. The error is: Unexpected character in bracket expression. This is the code of error_brack