From: Max Williams Date: 2008-11-13T22:36:36+09:00 Subject: Re: '#' characters are breaking my regexp Phlip wrote: > > "abc\\#def" > > When you mash like /#{string}/, the inserted item is not treated as a > literal string, but as a fragment of Regexp notation. So either first > call > Regexp.escape(string) on it, or make it a valid regexp. > > Next, "" might interpret \# as an escape in string notation, so escape > _that_ with \\#. > > And I always use '' unless I need the special powers of a "". So > 'abc\#def' > will work, because '' refrains from escaping anything that it doesn't > need > to. Still no joy i'm afraid: >> string = 'abc#def' => "abc#def" >> /#{string}/ => abc >> Regexp.escape(string) => "abc\\#def" >> Regexp.new(Regexp.escape(string)) => abc -- Posted via http://www.ruby-forum.com/.