Is there any way to simplify the following code so it looks clearer and more elegant?
The following code returns a collection of values found in a collection of texts, using Linq and regex:
IEnumerable<double> _results = pages.Select(result => {
Regex _regex = new Regex("<my regex here>", RegexOptions.None);
MatchCollection _matches = _regex.Matches(result);
double _number = 0.0;
foreach (Match _match in _matches) {
if (_match.Groups["value"].Value.Contains("("))
break;
else
double.TryParse(_match.Groups["value"].Value, out _number);
}
return _number;
});
As you can see, the regex is tricky, it is basically returning the last value found in each text before a condition is met, and that is the desired outcome.
How could you simplify the previous code looking for elegance? Memory and CPU utilization is not a problem.