How can I iterate a MatchCollection Index property of each Match
most efficiently? I have many Regex
objects in my code and I need to iterate through all Match
indices but in the VS profiler I see that a simple Linq query
regex.Matches(text).Cast<Match>().Select(x => x.Groups[1].Index)
and the inside function:
IEnumerator.MoveNext()
takes almost half of the execution time. Is there some way to hardcode this? Maybe pointer jumps through internal structures or some other methods to avoid IEnumerable<T>
?