Simple:
var match = Regex.Match(text, regExpression); string result = ""; if(match.Success) result = match.Value;
Deleting inconsistent characters is the same as storing matching characters. This is what we are doing here.
If it is possible that the expression matches several times in the text, you can use this:
var result = Regex.Matches(text, regExpression).Cast<Match>() .Aggregate("", (s, e) => s + e.Value, s => s);
Daniel Hilgarth
source share