From: Gabriele Marrone Date: 2006-11-14T02:45:20+09:00 Subject: Re: regular expression too big On 12/nov/06, at 15:30, Peter Schrammel wrote: > Hi, > > got problem with big regexes: > I have a regex of about 70000+ words concated with '|' that I'd > like to > match as a regex. /bla|blub|foo|bar|.....(70000)/ > > But unfortunately ruby gives me a 'regular expression too big' if I'm > trying to build such a thing. > I had a look at the regex.c code and saw the limit of 1 << 16 bytes > for > regexes. Is there a way around this (without going down to 2000 > words) ? I friend of mine told me to suggest you to system() a perl script which does the job :P However, since he was just kidding, I think I'll suggest you something like this: class String def include_at_least_one_of?(words) words.find { |w| include? w } end end my_words = %w(bla blub foo bar) "zump blub asd".include_at_least_one_of? my_words # => "blub" "nah none included".include_at_least_one_of? my_words # => nil You probably don't want to hack core classes in order to do this, but you get the idea. > > Thanks for any hint > > Peter > -- Gabriele Marrone