From: Intransition Date: 2009-12-07T01:21:38+09:00 Subject: Re: Regexp.escape with un-escapes On Dec 6, 10:33 am, Marnen Laibow-Koser wrote: > Why, yes!  Use a regexp to find the (( )) bits, and then extract them, > don't escape them, and paste the whole regexp together.  It's a bit > ironic to me that in a regexp-handling routine, you're doing brute-force > index searches. :) You are right, it is ironic! Your suggestion helped some. I came up with: def __when_string_to_regexp(str) rexps = [] str = str.gsub(/\(\((.*?)\)\)/) do |m| rexps << ['(' + $1 + ')'] "%s" end str = Regexp.escape(str) str = str % rexps str = str.gsub(/(\\\ )+/, '\s+') Regexp.new(str, Regexp::IGNORECASE) end It's still not perfect b/c it means end users won't be able to use "%s" in a string without it messing up --stitching it back together seems to be the hard part. But I'll keep working on it. Thanks.