If the only part of the example you don't understand is the callback, consider that:
std::for_each(m1, m2, ®ex_callback);
approximately equivalent:
for (; m1 != m2; ++m1){ class_index[(*m1)[5].str() + (*m1)[6].str()] = (*m1).position(5); }
Assuming that in your case you want to keep all matches in a vector, you should write something like:
//Warning, untested: boost::sregex_iterator m1(text.begin(), text.end(), expression); boost::sregex_iterator m2; std::vector<std::string> tokens; for (; m1 != m2; ++m1){ tokens.push_back(m1->str()). }
Γric Malenfant
source share