In computing and telecommunication, an escape character is a character that invokes an alternative interpretation on the following characters in a character sequence. An escape character is a particular case of metacharacters. Generally, the judgement of whether something is an escape character or not depends on the context.
In the telecommunications field, escape characters are used to indicate that the following characters are encoded differently. This is used to alter control characters that would otherwise be noticed and acted on by the underlying telecommunications hardware, such as illegal characters. In this context, the use of escape characters is often referred to as quoting.
An escape character may not have its own meaning, so all escape sequences are of two or more characters.
Escape characters are part of the syntax for many programming languages, data formats, and communication protocols. For a given alphabet an escape character's purpose is to start character sequences (so named escape sequences), which have to be interpreted differently from the same characters occurring without the prefixed escape character.
The functions of escape sequences include:
Generally, an escape character is not a particular case of (device) control characters, nor vice versa. If we define control characters as non-graphic, or as having a special meaning for an output device (e.g. printer or text terminal) then any escape character for this device is a control one. But escape characters used in programming (such as the backslash, "\") are graphic, hence are not control characters. Conversely most (but not all) of the ASCII "control characters" have some control function in isolation, therefore they are not escape characters.
In many programming languages, an escape character also forms some escape sequences which are referred to as control characters. For example, line break has an escape sequence of .
JavaScript uses the (backslash) as an escape character for:[1] [2]
The and escapes are not allowed in JSON strings.Example code:
The ASCII "escape" character (octal:, hexadecimal:, or, in decimal,, also represented by the sequences or) is used in many output devices to start a series of characters called a control sequence or escape sequence. Typically, the escape character was sent first in such a sequence to alert the device that the following characters were to be interpreted as a control sequence rather than as plain characters, then one or more characters would follow to specify some detailed action, after which the device would go back to interpreting characters normally. For example, the sequence of, followed by the printable characters, would cause a Digital Equipment Corporation (DEC) VT102 terminal to move its cursor to the 10th cell of the 2nd line of the screen. This was later developed into ANSI escape codes covered by the ANSI X3.64 standard. The escape character also starts each command sequence in the Hewlett-Packard Printer Command Language.
An early reference to the term "escape character" is found in Bob Bemer's IBM technical publications, who is credited with inventing this mechanism during his work on the ASCII character set.[3]
The Escape key is usually found on standard PC keyboards. However, it is commonly absent from keyboards for PDAs and other devices not designed primarily for ASCII communications. The DEC VT220 series was one of the few popular keyboards that did not have a dedicated Esc key, instead of using one of the keys above the main keypad. In user interfaces of the 1970s–1980s it was not uncommon to use this key as an escape character, but in modern desktop computers, such use is dropped. Sometimes the key was identified with AltMode (for alternative mode). Even with no dedicated key, the escape character code could be generated by typing while simultaneously holding down .
Many modern programming languages specify the double-quote character as a delimiter for a string literal. The backslash escape character typically provides two ways to include double-quotes inside a string literal, either by modifying the meaning of the double-quote character embedded in the string (becomes), or by modifying the meaning of a sequence of characters including the hexadecimal value of a double-quote character (becomes).
C, C++, Java, and Ruby all allow exactly the same two backslash escape styles. The PostScript language and Microsoft Rich Text Format also use backslash escapes. The quoted-printable encoding uses the equals sign as an escape character.
URL and URI use %-escapes to quote characters with a special meaning, as for non-ASCII characters. The ampersand character may be considered as an escape character in SGML and derived formats such as HTML and XML.
Some programming languages also provide other ways to represent special characters in literals, without requiring an escape character (see e.g. delimiter collision).
The Point-to-Point Protocol (PPP) uses the octet (or ASCII: