From: dblack@... Date: 2003-02-23T12:49:43+09:00 Subject: Re: String.to_re ?? Hi -- On Sun, 23 Feb 2003, Mattia Peronio 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/ David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav