From: Phlip Date: 2008-11-13T22:27:20+09:00 Subject: Re: '#' characters are breaking my regexp >>> string = "abc#def" > => "abc#def" >>> /#{string}/ > => abc >>> string = "abc\#def" "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.