开发者

Grabbing all regex matches of "$#" from a string

开发者 https://www.devze.com 2023-03-15 14:01 出处:网络
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.

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.

Here's an example of a string:

"This that $1 who $2"

Here's what I have so far using vb.net:

Dim wordSplitMatches As Match = Regex.Match("This that $1 who $2", "(\$\d+)+")

This works great for grabbing the $1 but how d开发者_开发问答o I set it up so that I get multiple groups with all the matches in?

This is the output at the moment:

? wordsplitmatches.groups(1).value
"$1"
? wordsplitmatches.groups(2).value
""


Regex.Match only returns the first match.

Use Regex.Matches to return all matches.

0

精彩评论

暂无评论...
验证码 换一张
取 消