我正在使用新版本的boost 1.42,我想使用正则表达式和命名子组。下面是一个例子。获取名称子组
std::string line("match this here FIELD=VALUE in the middle");
boost::regex rgx("FIELD=(?<VAL>\\w+)", boost::regex::perl);
boost::smatch thisMatch;
boost::regex_search(line, thisMatch, rgx);
你知道如何获取比赛内容吗? 传统的方式是
std::string result(mtch[1].first, mtch[1].second);
但我不想用这种方式。
我想像往常一样在Perl和正则表达式中使用子组的名称。 我试过了,但没有奏效。
std::string result(mtch["VAL"].first, mtch["VAL"].second);
您知道如何使用子组的名称获取值吗?
感谢 AFG
你想要的方式和你不想要的方式有什么区别?这些陈述完全相同。 – kennytm 2010-03-12 12:59:21
你说得对。我刚刚更改了示例中的代码 – 2010-03-12 15:59:24
再次!看看下面'因为我找到了我需要的东西! 周末愉快! – 2010-03-12 16:21:06