抢占"$#"的所有正则表达式匹配项从一个字符串 [英] Grabbing all regex matches of "$#" from a string
本文介绍了抢占"$#"的所有正则表达式匹配项从一个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个字符串,其中包含多个美元符号实例,后跟一个正数.我需要使用正则表达式获取每个实例.
I have a string that contains multiple instances of a dollar sign followed by a positive number. I need to grab each instance out using regex.
这是一个字符串示例:
"This that $1 who $2"
这是我到目前为止使用vb.net的内容:
Here's what I have so far using vb.net:
Dim wordSplitMatches As Match = Regex.Match("This that $1 who $2", "(\$\d+)+")
这对于抓取$ 1很有用,但是如何设置它,以便我可以将所有匹配项都包含在多个组中?
This works great for grabbing the $1 but how do I set it up so that I get multiple groups with all the matches in?
这是当前的输出:
? wordsplitmatches.groups(1).value
"$1"
? wordsplitmatches.groups(2).value
""
推荐答案
Regex.Match仅返回第一个匹配项.
Regex.Match only returns the first match.
使用 Regex.Matches 返回所有匹配项.
这篇关于抢占"$#"的所有正则表达式匹配项从一个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文