Search code examples
c#regexpicasa

C# get text between brackets


I have string

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

I need to get 2 strings containing in rect64('string')

So answer will be array of strings : 3f845bcb59418507, 9eb15e89b6b584c1.

Should I use Regex.Match? and how it can be done?


Solution

  • Use Regex.Matches method:

    For example:

    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
    }
    

    See a demo: http://ideone.com/Oayuo5