I have the following code that works, but would like to speed it up using LINQ (or something else) to find if any of the Regex search strings are in the target.
List<Regex> Filters = new List<Regex>();
Filters.Add(new Regex("string1", RegexOptions.IgnoreCase));
Filters.Add(new Regex("string2", RegexOptions.Compile));
...
bool found = false
string target = "string which may contain string1 or string2 or neither";
foreach (Regex r in Filters) {
if (r.IsMatch(target)) {
found = true;
break; // get out as soon as found
}
}
if (found) { // do stuff }
The search is currently taking a long time for the large files being processed. Is there a way to make .Any or .First get this done more efficiently?