Getting index of matched pattern in Boost::regex
I need to get the index at which the pattern is found while iterating through each loop.
I tried with distance but I am getting compile time error.
Is it possibe? If yes, What will be best way to get it??
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
void test2()
{
std::string text = "I am <single angle bracket> trying to use [single square bracket] [[double square bracket]] Boost::regex library. <single angle bracket>";
std::string::const_iterator start = text.begin();
std::string::const_iterator end = text.end();
boost::regex pattern("((<.*?>)|(\\[.*?\\]))");
boost::smatch what;
boost::match_flag_type flags = boost::match_default;
try
{
if(boost::regex_search(text, what, pattern))
{
for(unsigned i = 0; i < what.size(); ++i)
{
std::cout << what[i] << std::endl;
}
// update search position:
start = what[0].second;
//std::cout << std::distance(start, end);
// update flags:
flags |= boost::match_prev_avail;
flags |= boost::match_not_bob;
}
}
catch(std::runtime_error ex)
{
}
}
|
Also any advice for improving this code will be very helpful to me.
Thanks
Last edited on
Topic archived. No new replies allowed.