如何在 xpressive 中迭代命名组?
假设我有一个像这样的 sregex 对象:
boost::xpressive::sregex::compile("(?P<firstword>\\w+) (?<secondword>\\w+)!");
尽管 xpressive 支持命名组,但我无法在 xpressive 文档中找到任何与此相关的参考。
我知道可以迭代组就可以了,但是我将如何访问组名(如果组有名称)?
那么,我将如何迭代命名组?
Say I have a sregex
object like this one:
boost::xpressive::sregex::compile("(?P<firstword>\\w+) (?<secondword>\\w+)!");
I have not been able to find any reference in the xpressive documentation regarding this, despite xpressive supporting named groups just fine.
I know that it is possible to iterate through groups is just fine, but how would I access the groupname (if the group has a name at all)?
So, How would I iterate through the named groups?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设我们有您正在处理的整个正则表达式,
在我看来,您似乎正在尝试创建一个与这两个匹配的正则表达式
命名捕获,因此尝试迭代命名捕获是没有用的。
你只需要尝试类似的事情。
如果正则表达式是更复杂模式的一部分,为什么不使用静态命名的 capture :
http://www.boost.org/doc/libs/1_41_0/doc/html/xpressive/user_s_guide.html#boost_xpressive.user_s_guide.named_captures.static_named_captures
Supposing that we have the whole regular expression you are working on,
iIt seems to my point of view that you are trying to create a regular expression that match both of the
the named capture, so it is useless to try to iterate over named capture.
You simply have to try something like that.
If the regular expression is part of a more complex pattern why not use the static named capture :
http://www.boost.org/doc/libs/1_41_0/doc/html/xpressive/user_s_guide.html#boost_xpressive.user_s_guide.named_captures.static_named_captures