How can I get the name of the group corresponding to the pattern match using Boost regular expressions?
The following will output the matched expression to the given pattern. But how can I get the corresponding named group?
boost::regex pattern("(?<alpha>[0-9]*\\.?[0-9]+)|(?<beta>[a-zA-Z_]+)");
string s = "67.2 x 7 I am";
string::const_iterator start = s.begin();
string::const_iterator end = s.end();
boost::sregex_token_iterator i(start, end, pattern);
boost::sregex_token_iterator j;
for ( ;i != j; ++i)
{
cout << *i << endl;
// '67.2' and '7' belongs to "alpha"
// 'x', 'I', 'am' belongs to "beta"
}
You can get it from match_result It is for xpressive, but the same should work for Boost.Regex
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