我想从字符串中提取数字,格式如下:
string foo="something%4%something2%5%";
Run Code Online (Sandbox Code Playgroud)
我如何用Regex写这个?
//pseudocode
foo.GetDigits("%"+{int}+"%").ToArray();
Run Code Online (Sandbox Code Playgroud)
谢谢!
var matches = Regex.Matches(foo, @"%(\d+?)%").Cast<Match>()
.Select(m => m.Groups[1].Value)
.ToList();
Run Code Online (Sandbox Code Playgroud)