【发布时间】:2013-05-21 09:01:07
【问题描述】:
我有字符串"SolutionAN ANANANA SolutionBN" 我想返回所有以Solution 开头并以N 结尾的字符串。
使用正则表达式时boost::regex regex("Solu(.*)N");
我的输出为SolutionAN ANANANA SolutionBN。
虽然我想以SolutionAN 和SolutionBN 的身份退出。我是正则表达式的新手,任何帮助都将不胜感激。
如果我正在使用代码片段
#include <boost/regex.hpp>
#include <iostream>
int main(int ac,char* av[])
{
std::string strTotal("SolutionAN ANANANA SolutionBN");
boost::regex regex("Solu(.*)N");
boost::sregex_token_iterator iter(strTotal.begin(), strTotal.end(), regex, 0);
boost::sregex_token_iterator end;
for( ; iter != end; ++iter ) {
std::cout<<*iter<<std::endl;
}
}
【问题讨论】: