Boost logo

Boost Users :

From: John Maddock (john_at_[hidden])
Date: 2005-10-16 11:20:51


> So, how could I achieve that? Could I still use boost::regex_grep?

There are a couple of options: one would be to combine all your regexes into
one big expression, each with a different sub-expression index so you can
tell which one was matched:

(expression-1)|(expression-2)|(expression-3)

The other option would be to call regex_grep (which has been deprecated in
favour of regex_iterator BTW) with non-constant iterators, then you could
fill the area matched with whitespace in preparation for the next match:

std::string text(whatever);
boost::regex re(expression_text);
boost::regex_iterator<std::string::iterator> i(text.begin(), text.end(),
re), j;
while(i != j)
{
    // do something with *i here, then:
    std::fill((*i)[0].first, (*i)[0].second, ' ');
    ++i;
}

Get the idea?

John.


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