In IRB if I pass a string like "/domain/path" to Regexp.escape it just returns it the same. I thought that forward slashes are supposed to be escaped with a backslash? Am I missing something here?
+3
A:
No, forward slashes do not need escaping. Backslashes need to be escaped (by another one),
e.g. test\test
-> test\\test
enbuyukfener
2010-02-05 03:53:50
+1
A:
Also, the only reason why you would need to escape /
characters is because it is your delimiter for the regexp, if you specify other type of delimiters (or make an instance of the Regexp class) you won't have this issue:
/^hello\/world$/ # escaping '/' just to say: "this is not the end"
%r"^hello/world$" # no need for escaping '/'
Regexp.new('^hello/world$') # no need for escaping '/'
Roman Gonzalez
2010-02-05 16:58:53