I am using Boost to match substrings in a string. Io iterate over the results, I need to use regex_iterator()
.
That is the only usage example I have found, but I do not understand the callback. Could someone give me an example uage of the function?
Let us assume that my input text is:
"Hello everybody this is a sentense
Bla bla 14 .. yes
date 04/15/1986
"
I want to get:
"Hello" "everybody" "this" "is" "a" "sentense" "bla" "yes" "date"
If the only part of the example you don't understand is the callback, consider that:
std::for_each(m1, m2, ®ex_callback);
is roughly equivalent to:
for (; m1 != m2; ++m1){
class_index[(*m1)[5].str() + (*m1)[6].str()] = (*m1).position(5);
}
Assuming that, in your case, you want to store all the matches in a vector, you would 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()).
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With