From: Marnen Laibow-Koser Date: 2009-12-07T00:33:49+09:00 Subject: Re: Regexp.escape with un-escapes Thomas Sawyer wrote: > Hi-- > > I want to translate a string into a regular expression, but I want to > "un-escape" portions as raw regexp. For example: > > "here is a setting 'a' equal to ((\d+))" > > So I want to Regexp.escape the string, before I pass it to Regexp.new, > but I want what's in the (( )) to stay exactly the same with the > double-parens removed. > > I know that has to be a fairly concise way to do this, but all I've > come up with is some very ugly brute force code that iterates back and > forth using index '((' and index '))'. > > Any suggestions? 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. :) Best, --  Marnen Laibow-Koser http://www.marnen.org marnen@marnen.org -- Posted via http://www.ruby-forum.com/.