Where can I find string escape sequences in the Ruby documentation?
Below are some of the more common escape sequences that can appear inside of double quotes.
\"
– double quote ("
)
\\
– single backslash (\
)
\a
– bell/alert (plays a tone)
\b
– backspace (removes previous character, shifts cursor back one position)
\r
– carriage return (moves cursor to beginning of line)
\n
– newline (moves cursor to next line)
\s
– space (
)
\t
– tab (
)
Please see the official documentation (or on ruby-doc.org) which has been updated with a full list of supported escape characters:
\a bell, ASCII 07h (BEL)
\b backspace, ASCII 08h (BS)
\t horizontal tab, ASCII 09h (TAB)
\n newline (line feed), ASCII 0Ah (LF)
\v vertical tab, ASCII 0Bh (VT)
\f form feed, ASCII 0Ch (FF)
\r carriage return, ASCII 0Dh (CR)
\e escape, ASCII 1Bh (ESC)
\s space, ASCII 20h (SPC)
\\ backslash, \
\nnn octal bit pattern, where nnn is 1-3 octal digits ([0-7])
\xnn hexadecimal bit pattern, where nn is 1-2 hexadecimal digits ([0-9a-fA-F])
\unnnn Unicode character, where nnnn is exactly 4 hexadecimal digits ([0-9a-fA-F])
\u{nnnn ...} Unicode character(s), where each nnnn is 1-6 hexadecimal digits ([0-9a-fA-F])
\cx or \C-x control character, where x is an ASCII printable character
\M-x meta character, where x is an ASCII printable character
\M-\C-x meta control character, where x is an ASCII printable character
\M-\cx same as above
\c\M-x same as above
\c? or \C-? delete, ASCII 7Fh (DEL)
If you find anything to add or fix, we welcome feedback and contributions via pull-request on GitHub or via our issue tracker.
While opinions vary as to what constitutes the "official" documentation, I would offer http://www.ruby-doc.org/core-2.0.0/doc/syntax/literals_rdoc.html#label-Strings as an answer to your question.