c++ - boost 正则表达式 : Getting the Named Group

标签 c++ regex boost

如何使用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"
}

最佳答案

You can get it from match_result它适用于xpressive,但同样适用于Boost.Regex

关于c++ - boost 正则表达式 : Getting the Named Group,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34383123/

相关文章:

C# 正则表达式匹配示例

c++ - Boost.coroutine 单向 : Legal to get reference to stack variable on suspension?

c++ - 如何正确从 vector 返回 unique_ptr?

c++ - 以编程方式禁用 firefox 扩展

c++ - "end"不能在模板函数中使用

regex - 确定行是否包含 1-4 个特定字符的正则表达式

c++ - 在 C++ 中,这段代码是什么意思?

php - 带有序通配符的 MySQL 搜索,并提取它们的值

c++ - 在没有物理连接的情况下写入时,boost async tcp 客户端不会返回错误

c++ - 安全地取消 boost asio 截止时间计时器