From: Brian Candler Date: 2009-12-07T02:45:42+09:00 Subject: Re: Regexp.escape with un-escapes There is a feature in String#split (documented in 1.9, undocumented in 1.8.6 but still present) whereby if the split RE contains capture groups, those capture groups will be included in the resulting array. >> s = 'here is (a) setting \'a\' equal to ((\d+))' => "here is (a) setting 'a' equal to ((\\d+))" >> Regexp.new(s.split(/(\(\(.*?\)\))/).map { |x| x =~ /\A\((\(.*\))\)\z/ ? $1 : Regexp.escape(x) }.join) => /here\ is\ \(a\)\ setting\ 'a'\ equal\ to\ (\d+)/ -- Posted via http://www.ruby-forum.com/.