In PHP you need to use preg_quote() to escape all the characters in a string that have a particular meaning in a regular expression, to allow (for example)
preg_quote()
You want Regexp.escape.
Regexp.escape
str = "[...]" re = /#{Regexp.escape(str)}/ "la[...]la[...]la".gsub(re,"") #=> "lalala"