【发布时间】:2018-04-29 05:46:52
【问题描述】:
我正在尝试在 c++11 中使用正则表达式,但我的代码总是抛出 Invalid special open parenthesis. 的 std::regex_error。尝试在字符串中查找第一个重复字符的最小示例代码:
std::string regexp_string("(?P<a>[a-z])(?P=a)"); // Nothing to be escaped here, right?
std::regex regexp_to_match(regexp_string);
std::string target("abbab");
std::smatch matched_regexp;
std::regex_match(target, matched_regexp, regexp_to_match);
for(const auto& m: matched_regexp)
{
std::cout << m << std::endl;
}
为什么会出现错误以及如何修复此示例?
【问题讨论】:
标签: c++ regex string c++11 match