Escape sequence

Updated: 10/18/2022 by Computer Hope

Invented by Bob Bemer, an escape sequence is two or more characters that often begin with an escape character that tell the computer to perform a function or command. Below is a listing of some commonly used escape sequences used in programming languages and 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 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 regex (regular expression) can allow you to find and replace characters or perform a special feature. For example, in the example below of a Perl regular expression in a while loop we're deleting any line beginning with a return.

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

Control character, Escape, Escape character, Printf, Programming terms, Regex, Reserved character