I am trying to get values between {} and %% in the same Regex. This is what I still have. I can successfully get the values individually for each, but I was curious to know how I can combine both.
var regex = new Regex(@"%(.*?)%|\{([^}]*)\}");
String s = "This is a {test} %String%. %Stack% {Overflow}";
The expected response for the specified string
test
String
Stack
Overflow
Individual Regular Expression
@"%(.*?)%" gives me String and Stack
@"\{([^}]*)\}" gives me test and Overflow
Below is my code.
var regex = new Regex(@"%(.*?)%|\{([^}]*)\}");
var matches = regex.Matches(s);
foreach (Match match in matches)
{
Console.WriteLine(match.Groups[1].Value);
}
source
share