I noticed here at String that contains all ascii characters they skip the first ASCII characters. Then here they list a bunch of control codes like \cA
, but they only work for regular expressions. Wikipedia lists about 10 such as \n
and \r
. Wondering if you can write the other ones in backslash notation somehow, or you must resort to unicode \u{...}
or hex \x{...}
.
Asked
Active
Viewed 358 times
0

Lance
- 75,200
- 93
- 289
- 503
-
You have to use the numeric escapes for the others. – Pointy Aug 24 '18 at 14:10
-
See this too in case you haven't: https://en.wikipedia.org/wiki/ASCII#Control_characters. Specifically, the table in the section. – Roope Aug 24 '18 at 14:16
-
I'd definitely call `\x0A` "backslash notation"? Not sure what you are looking for – Bergi Aug 24 '18 at 14:18
1 Answers
2
This is covered by the spec (of course :-) ), specifically where it talks about SingleEscapeCharacter:
SingleEscapeCharacter :: one of
' " \ b f n r t v
Ignoring '
, "
, and \
which aren't control characters, that gives us:
\b
is backspace (character 8)\f
is formfeed (character 12)- As you know,
\n
is newline and\r
is carriage return \t
is tab (character 9)\v
is vertical tab (character 11)
So other than those six, you have to use \uNNNN
, \xXX
, or \u{N+}
(ES2015+) for the others. Or of course use typing tricks to type them literally, which may work in some cases but is almost certainly a Very Bad Idea™. :-)
Being pedantic, these aren't ASCII, they're Unicode. But this is a place where Unicode intentionally overlaps ASCII, so...

T.J. Crowder
- 1,031,962
- 187
- 1,923
- 1,875
-
1You might want to mention the deprecated [`LegacyOctalEscapeSequence`](http://ecma-international.org/ecma-262/#sec-additional-syntax-string-literals) that allows to omit the `x` or `u` prefix – Bergi Aug 24 '18 at 14:22
-
1@Bergi - ...or we could try to let it slip out of the general consciousness... ;-) – T.J. Crowder Aug 24 '18 at 14:30