After a day of hacking and reading, I was not lucky with a regex engine, I hope someone here can help.
I want to capture the first field from each row, where the last field corresponds to some input.
string input =
"449 a dingo ate my baby THING\n"
"448 a dingo ate my baby THING\n"
"445 a dingo ate my baby BOOGNISH\n"
"446 a dingo ate my baby BOOGNISH\n"
"447 a dingo ate my baby STUFF\n";
Let's say I give my regular expression the following line ...
string re = "^([0-9]+).+?boognish$";
boost::regex expression(re,boost::regex::perl | boost:regex::icase);
and then adjust the match
const int subs[] = { 0, 1 };
boost::sregex_token_iterator it(input.begin(), input.end(), expression, subs);
boost::sregex_token_iterator end;
while ( it != end )
{
fprintf(stderr,"%s|\n", it->str().c_str());
*it++;
}
Here is the result that I get from the promotion, keep in mind that I asked for the whole line and group 1, I also asked for "|" so we can easily see the end of the line:
449 a dingo ate my baby THING
448 a dingo ate my baby THING
445 a dingo ate my baby BOOGNISH|
449|
446 a dingo ate my baby BOOGNISH|
446|
I really want 445 | and 446 | only, but he gives me 449 (until he gets to the first BOGNIS), and then 446. I tested it on other reparators, and it seems to work fine. What am I doing wrong with the promotion?
Thank you in advance!