Hi,

At Sun, 23 Feb 2003 12:49:43 +0900,
dblack / candle.superlink.net wrote:
> > I will explain you my problem, with a short example code:
> >
> > ------------------------------------------------
> > a = "Good this kind of work!"
> > b = "this kind"
> > puts a[Regexp.new("G.*#{b}.*rk!")]               >> Good this kind of work!"
> >
> > a = "Good this+kind of work!"
> > b = "this+kind"
> > puts a[Regexp.new("G.*#{b}.*rk!")]             >> nil
> > -----------------------------------------------
> >
> > I woud like to know if you can implement a method string.to_re which converts a string to a regular expression, i.e.:
> >
> > Good this+kind of work        >>>>   Good this[+]kind of work
> 
> Try Regexp.escape:
> 
>   Regex.new(Regexp.escape("abc+def"))  # => /abc\+def/

In short:

  puts a[/G.*#{Regexp.quote(b)}.*rk!/]

Ruby doesn't have Perl-like \Q and \E.

-- 
Nobu Nakada