如何使用Boost正则表达式获取与模式匹配相对应的组名?
以下内容将匹配的表达式输出到给定的模式。但是如何获得相应的命名组呢?
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"
}