【发布时间】:2010-08-29 04:14:13
【问题描述】:
我正在使用 tr1::regex 尝试从字符串中提取一些匹配项。一个示例字符串可以是
asdf werq "one two three" asdf
我想摆脱这种情况:
asdf
werq
one two three
asdf
引号中的内容组合在一起,所以我尝试使用正则表达式\"(.+?)\"|([^\\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
我做错了什么?
【问题讨论】: