Shalom.
I need to go over a file, and check for each line if it matches a Regex
from a list of expressions.
(If it matches ANY of the expressions, this is good enough).
I have put the Regex's in an array, but it seems to take too long to
compare each line to all Regex's.
So i thought maybe there's a way to put Regex's in a hashtable, and
make the search for a match a bit faster.
If anyone has an idea how to do this, i will be happy to hear.
Thanks.
Ofira.
Marc Gravell - 23 Nov 2006 16:03 GMT
No; the hashtable would only help you retreive a *specific* regex from some
predefined key; has nothing to do with matching; the array was already
probably your best bet.
If in 2.0, you could consider compiling the Regex; this should help. Also
check for back-references and other expensive Regex things. Ensure you are
short-circuiting - i.e. if a line you've matches *one* Regex, then stop
looking. How are you processing the file? Line by line (StreamReader)? or as
an entire string? Finally, check if there are any logical short-cuts, i.e.
if it doesn't start like <x>, then it can't *possibly* match these 5 Regex,
so don't bother looking...
Marc