I'm trying to get the values between {} and %% in a same Regex. This is what I have till now. I can successfully get values individually for each but I was curious to learn about how can I combine both.
var regex = new Regex(@"%(.*?)%|\{([^}]*)\}");
String s = "This is a {test} %String%. %Stack% {Overflow}";
Expected answer for the above string
test
String
Stack
Overflow
Individual regex
@"%(.*?)%" gives me String and Stack
@"\{([^}]*)\}" gives me test and Overflow
Following is my code.
var regex = new Regex(@"%(.*?)%|\{([^}]*)\}");
var matches = regex.Matches(s);
foreach (Match match in matches)
{
Console.WriteLine(match.Groups[1].Value);
}