jeudi 4 avril 2019

boost regex search - how to read result

I use regex to get a text placed between tags:

std::string data = "<tagA>aaa</tagA><tagB>bbb</tagB><tagC>ccc</tagC>";
boost::regex expr("<tagB>(.*)</tagB>");
boost::smatch smatch;

boost::regex_search(data, smatch, expr);
//smatch[0] <tagB>bbb</tagB>
//smatch[1] bbb

I'm looking for a string bbb which is stored in smatch[1] but reading something based on numeric index doesn't look good. Is there any other way to get a result ? Maybe I should modify regex to get a single element smatch or use other interface ?

Aucun commentaire:

Enregistrer un commentaire