|
Boost Users : |
From: david v (danova_fr_at_[hidden])
Date: 2007-07-04 04:24:28
Hello,
I'm trying to use regex_search to look for regular expressions.
regex = (david|divad)
stringtosearch = "david"
So I'm looking for regex above in the string "david". As you see a very
basic example. I'm expecting to find two hits, but I thought I should
recover "david" and "david" and not twice the same match "david" ???
Here is a snippet of the code:
....
boost::smatch match;
start = stringtosearch.begin(); //that would be the start of "david"
end = stringtosearch.end(); // that would be the end of "david"
old_pos = 0;
cout << "Looking for regex:" << regex << " in string " << stringtosearch <<
endl;
while (boost::regex_search(start,end,match,regex))
{
old_pos += match.position()+1;
std::string t = match[0];
std::cout << "\tFound:" << match[0] << endl;
old_pos += match.length();
start = match[0].second;
}
catch(const std::exception ®ex)
{
std::cerr << "Exception:" << regex.what() << std::endl;
exit(-1);
}
Here is the output:
Looking for regex:(david|divad) in string david
Found david
Looking for regex:(david|divad) in string david
Found david
As you can see, pattern "david" is found twice ??? I was expecting two
different patterns to be found "david" and "divad".
By the way how can I recover the total number of matches found ??
thanks,
david
_________________________________________________________________
MSN Messenger : discutez en direct avec vos amis !
http://www.msn.fr/msger/default.asp
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net