Ruby code adding single \ to escape #, instead of adding \\

51 Views Asked by At

ruby adding single \ to escape # instead of double backslash

for example, the # in string sd@# is preceded with single \ like this sd@\# automatically. I think it should add \\ (double backslash) to escape #.

Is it a bug in ruby syntax? if not is there a way to escape it manually

Please help

1

There are 1 best solutions below

3
Albin Mathew On

You can use a single \to escape #. Also, there is no need for escaping # in strings. Both mystring# and mystring\# will give output mystring#