我正在使用 tr1::regex 尝试从字符串中提取一些匹配项。一个示例字符串可能是
asdf werq "one two three" asdf
我想摆脱这种情况:
asdf
werq
one two three
asdf
将引号中的东西组合在一起,所以我正在尝试使用 regex \"(.+?)\"|([^\\s]+)
。我正在使用的代码是:
cmatch res;
regex reg("\"(.+?)\"|([^\\s]+)", regex_constants::icase);
regex_search("asdf werq \"one two three\" asdf", res, reg);
cout << res.size() << endl;
for (unsigned int i = 0; i < res.size(); ++k) {
cout << res[i] << endl;
}
但输出
3
asdf
asdf
我究竟做错了什么?