On Jul 27, 2006, at 9:10 PM, 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.
>
>

Just guessing but I believe you want
/#{Regexp.escape(marker)}/

or Regexp.new(Regexp.escape(marker))


> -- 
> Simon Baird <simon.baird / gmail.com>