Escape sequence

Updated: 04/26/2017 by Computer Hope

Invented by Bob Bemer, an escape sequence is two or more characters that often begin with an escape character that tells the computer or software program to perform a function or command. Below is a listing of some of the commonly used and available escape sequences used in programming languages and some text editors.

\' Single quote
\" Double quote
\a Audible bell
\b Backspace
\f Form feed
\n Newline
\r Carriage return
\s A space or white space.
\t Horizontal tab

Below is an example of how an escape sequence appears to a computer and then how it is displayed to the user.

Hello\nHere is an example of text that uses\nescape sequences.

The above example with escape sequences would display the below text.

Hello
Here is an example of text that uses
escape sequences.

Finally, adding an escape sequence into a regular expression (regex) can allow you to find and replace characters or perform a special feature. For example, in the example below of a Perl regular expression we're finding any line that begins with a character return and deleting it.

while (<ofile>) {
$line = $_;
$line =~ s/^\n//g;
}

Escape, Programming terms, Regex