From: "David A. Black" Date: 2008-04-30T23:29:15+09:00 Subject: Re: Search string for occurneces of words stored in array Hi -- On Wed, 30 Apr 2008, Jens Wille wrote: > ok, i withdraw my post. david's just quicker... ;-) Yeah, but yours is cooler because you remembered Regexp.union :-) > Jens Wille [2008-04-30 16:18]: >> sentence =~ Regexp.union(*words) > one addition regarding the regexp, though. in case words may contain > special characters, it's safer to escape them first: > > sentence =~ Regexp.union(*words.map { |word| Regexp.escape(word) }) It actually does it for you: Regexp.union("a",".b") => /a|\.b/ David -- Rails training from David A. Black and Ruby Power and Light: INTRO TO RAILS June 9-12 Berlin ADVANCING WITH RAILS June 16-19 Berlin INTRO TO RAILS June 24-27 London (Skills Matter) See http://www.rubypal.com for details and updates!