C ++ 11正则表达式捕获组的名称 [英] C++11 Regex Capture Groups By Name

查看:227
本文介绍了C ++ 11正则表达式捕获组的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将基于boost的正则表达式转换为C ++ 11正则表达式。我有一个名为 url 的捕获组:

I am converting my boost-based regular expressions to C++11 regex. I have a capture group called url:

\s*?=\s*?(("(?<url>.*?)")|('?<url>.*?)'))

通过增强,如果您有 smatch ,则可以调用 match.str( url)以按名称获取捕获组。使用 std :: smatch ,我只能看到索引子匹配项。

With boost, if you had an smatch you could call match.str("url") to get the capture group by name. With std::smatch, I am only seeing indexed sub-matches.

如何访问使用std :: smatch类进行url捕获?

How can I get access to the url capture using the std::smatch class?

推荐答案

您不能使用c ++ 11标准命名捕获组。 C ++ 11正则表达式符合ECMAScript语法。这是一个说明所有内容的链接 http://www.cplusplus.com/reference/regex/ ECMAScript / 。即使您考虑一下这可能会令人失望,但真正的正则表达式将不支持此功能。

You cannot name a capture group with the c++11 standard. C++11 regex conforms to the ECMAScript syntax. Here is a link that explains it all http://www.cplusplus.com/reference/regex/ECMAScript/. Even though this maybe disappointing if you think about it a true regular expression will not support this it is extra.

这篇关于C ++ 11正则表达式捕获组的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆