i’m using a code to search number of strings and match them with one string.
my code:
foreach (string needle in list)
{
if (Regex.IsMatch(haystack,needle))
{
//do some stuff
}
}
is there any way to speedup the matching process?
If your regular expressions are reasonable then most likely your current approach is OK. You may want to consider using compiled regular expressions instead of static IsMatch with strings.
If you need more speed – consider better algorithms (i.e. start at http://en.wikipedia.org/wiki/String_searching_algorithm ), you may be able to construct faster search for all patterns combined than individual ones.
Note that as with any performance problem there is no replacement for measurements – try and compare.