C#在括号之间获取文本

时间:2014-03-17 13:40:02

标签: c# regex picasa

我有字符串

faces=rect64(3f845bcb59418507),8e62398ebda8c1a5;rect64(9eb15e89b6b584c1),d10a8325c557b085

我需要获得包含在rect64('string')

中的2个字符串

所以答案将是字符串数组:3f845bcb59418507,9eb15e89b6b584c1。

我应该使用Regex.Match吗?以及如何做到这一点?

3 个答案:

答案 0 :(得分:2)

尝试使用此正则表达式@"\(([^)]*)\)"

答案 1 :(得分:1)

使用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

答案 2 :(得分:1)

您可以使用

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();
相关问题