c#在括号之间获取文本
本文关键字:获取 取文本 之间 | 更新日期: 2023-09-27 17:50:47
我有一个字符串
faces=rect64(3f845bcb59418507),8e62398ebda8c1a5;rect64(9eb15e89b6b584c1),d10a8325c557b085
我需要得到2个字符串包含在rect64('string')
所以答案将是字符串数组:3f845bcb59418507, 9eb15e89b6b584c1.
我应该使用Regex.Match吗?怎样才能做到呢?
尝试使用这个正则表达式@"'(([^)]*)')"
使用Regex.Matches
方法:
String text = "faces=rect64(3f845bcb59418507),8e62398ebda8c1a5;rect64(9eb15e89b6b584c1),d10a8325c557b085";
Regex re = new Regex(@"rect64'(([a-f0-9]+)')");
foreach (Match match in re.Matches(text)) {
Console.WriteLine(match.Groups[1]); // print the captured group 1
}
查看演示:http://ideone.com/Oayuo5
可以使用
String input = "faces=rect64(3f845bcb59418507),8e62398ebda8c1a5;rect64(9eb15e89b6b584c1),d10a8325c557b085";
Regex regex = new Regex(@"(?<=rect64'()('w|'d)+");
string[] matches = regex.Matches(input).Cast<Match>().Select(m => m.Value).ToArray();