I\'m looking to extract:
50%
From a string that will have more or less this format:
The 50% is in here somewhere.
I\'d
I do not understand your reasoning why you want to use replace. Why go that way in the first place? There are methods in the Regex
class that allow you to precisely get all the desired matches. Your roundabout way at getting to your solution I find is pointless.
Just use Matches()
to collect the matches. You could then join them into the string that you wanted.
var str = "50% of 50% is 25%";
var re = new Regex(@"\d+%");
var ms = re.Matches(str);
var values = ms.Cast().Select(m => m.Value);
var joined = String.Join("", values); // "50%50%25%"