<分区>
我有这段代码片段,是我从网上找到的东西派生出来的:
std::regex pieces_regex("([a-z]+)\\.([a-z]+)", std::regex_constants::basic);
std::smatch pieces_match;
std::string fname = "foo.txt";
cout << " fname " << fname << endl;
if (std::regex_match(fname, pieces_match, pieces_regex)) {
std::cout << fname << '\n';
for (size_t i = 0; i < pieces_match.size(); ++i) {
std::ssub_match sub_match = pieces_match[i];
std::string piece = sub_match.str();
std::cout << " submatch " << i << ": " << piece << '\n';
}
}
pieces_regex 构造函数不适用于我的编译器,所以我不得不更改
std::regex pieces_regex("([a-z]+)\\.([a-z]+)");
到
std::regex pieces_regex("([a-z]+)\\.([a-z]+)", std::regex_constants::basic);
我的 regex_match 行现在没有返回任何内容,pieces_match 的大小为零。我尝试向 regex_match 添加几个不同的标志,如 basic 或 match_any,但没有帮助。 原始代码可以在这里找到: http://en.cppreference.com/w/cpp/regex/regex_match
有人知道我错过了什么吗?
谢谢!