使用正则表达式匹配一定长度的字符串中的数字

Sch*_*ime 0 c# regex

假设我有一个这样的字符串:"23423423",我想找到长度为2的所有数字,正则表达式为"[0-9] {2}"

现在我的短信给了我7场比赛:23,34,42,23,34,42,23

然而在c#中我似乎只得到4 23,42,34,42

我需要第一个场景但无法找到解决方案.

我试过regex.Match()和regex.Matches()没有运气.

谁知道怎么样?

Ale*_*lli 5

这个问题对一个非常类似的问题有一些解决方案,并且,根据它们中最简单的一个,你可以使用类似的东西:

Regex regexObj = new Regex("\d\d");
Match matchObj = regexObj.Match(subjectString);
while (matchObj.Success) {
    matchObj = regexObj.Match(subjectString, matchObj.Index + 1); 
}
Run Code Online (Sandbox Code Playgroud)