From: steve Date: 2009-10-15T17:15:21+09:00 Subject: Re: matching against a zillion patterns George George wrote: > i have some script in which i would like to match a string against > 'many' regular expressions patterns. > > def group(string) > if string=~ /pattern1 |patter2|pattern3|pattern(N)/ #where N =>100 > group =1 > else > .... > end > end > > My worry is the amount of patterns that i have (exceeding 400) and the > efficiency and sanity of such an approach.What would you advice? > > > Thank you. Are the matches randomly distributed across the patterns? If not, perhaps you could arrange for the most common patterns in the first search, the next most common in a subsequent search and so on. Also recall that compiled regexps can be assigned to variables or constants, including arrays. Regards Steve.