From: Daniel Baird Date: 2006-07-28T10:27:37+09:00 Subject: Re: Equivalent of perl's \Q in regexps? ------=_Part_157_25930700.1154050054837 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 7/28/06, Simon Baird wrote: > > marker = '***' > > code = <<-EOT > var x = 1 > //*** hello > function foo() {} > EOT > > p code.to_a.grep(/\*\*\*/) # -> ["//*** hello\n"] that's what I > want but using marker > > #p code.to_a.grep(/#{marker}/) # -> invalid regexp error > > p code.to_a.grep(/#{%q(marker)}/) # -> [], doesn't work > > > > In perl you can do /\Q$marker/ and it escapes $marker for the regexp. > > > Simon. > > -- > Simon Baird > > Maybe you want %r: regex = %r{^\s*[a-z]} -- Daniel Baird http://tiddlyspot.com (free, effortless TiddlyWiki hosting) http://danielbaird.com (TiddlyW;nks! :: Whiteboard Koala :: Blog :: Things That Suck) ------=_Part_157_25930700.1154050054837--