I have a dictionary defined as Dictionary<int, Regex>. There are a number of compiled Regex objects within this. This was done using C# .NET 4.
I’m trying to use a Linq statement to parse the dictionary and return an object that contains all of the dictionary Keys and the index of where each Regex was found in the specified text.
The IDs return fine, but I’m unsure of how to get the location of where the text was found. Can someone help me out?
var results = MyDictionary
.Where(x => x.Value.IsMatch(text))
.Select(y => new MyReturnObject()
{
ID = y.Key,
Index = ???
});
Use the
Indexproperty of theMatchclass instead of doing simpleIsMatch.Example:
Result