Question

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?

Was it helpful?

Solution 2

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

OTHER TIPS

Try to use this regex @"\(([^)]*)\)"

You can use

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();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top