I have and string \"SolutionAN ANANANA SolutionBN\"
I want to return all string which start with Solution
and end with N
.
Whi
The problem is that *
is greedy. Change to using the non-greedy version (note the ?
):
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;
}
}