escaping a string in Ruby

后端 未结 4 586
有刺的猬
有刺的猬 2021-02-05 16:39

I want to insert the following as the value for a variable in some Ruby:

`~!@#$%^&*()_-+={}|[]\\:\";\'<>?,./

Surrounding this in doub

4条回答
  •  面向向阳花
    2021-02-05 17:18

    <, and %q{} are your friends. Info on using them from the Programming Ruby The Pragmatic Programmer's Guide.

    Try mixing the various approaches:

    %q{`~!@#$%^&*()_-+}+"{}"+%q{=|[]\\:";'<>?,./}
    

    or alternatively, just use backslashes to escape the problematic chars:

    "`~!@\#$%^&*()_-+{}=|[]\\:\";'<>?,./"
    

提交回复
热议问题