有没有办法使捕获在正则表达式中重复任意次数? [英] Is there a way to have a capture repeat an arbitrary number of times in a regex?

查看:173
本文介绍了有没有办法使捕获在正则表达式中重复任意次数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将C ++ tr1 :: regex与ECMA regex语法一起使用。我想做的是解析标头并返回与标头中每个项目相关的值。

I'm using the C++ tr1::regex with the ECMA regex grammar. What I'm trying to do is parse a header and return values associated with each item in the header.

Header:

-Testing some text
-Numbers 1 2 5
-MoreStuff some more text
-Numbers 1 10

我想做的是找到所有的 -Numbers行,并用一个正则表达式将每个数字放入自己的结果中。如您所见,-Numbers行中可以有任意数量的值。目前,我只是在搜索 -Numbers([\s0-9] +),然后将该结果标记化。我只是想知道是否可以在单个正则表达式中查找和标记结果。

What I would like to do is find all of the "-Numbers" lines and put each number into its own result with a single regex. As you can see, the "-Numbers" lines can have an arbitrary number of values on the line. Currently, I'm just searching for "-Numbers([\s0-9]+)" and then tokenizing that result. I was just wondering if there was any way to both find and tokenize the results in a single regex.

推荐答案

不,有不是。

这篇关于有没有办法使捕获在正则表达式中重复任意次数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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