Tab character
A tab character is a typographical space commonly found at the beginning of a line of text. A computer's horizontal tab is represented as a single non-printable character, ASCII (American Standard Code for Information Interchange) value 9. The less-common vertical tab (ASCII 11) functions the same as a horizontal tab but vertically.
If formatting marks are enabled in your document editor, the tab character is displayed as a right arrow.
How many spaces are in a tab?
With early typewriters, the horizontal tab size was originally five characters. This size later evolved to eight characters because "8" was easier to calculate than "5."
Today's computers translate the tab character with software to a variable-width spacing. Common default tab widths are four spaces (in a monospaced text document) or half an inch (in a word processor).
However, no standard values exist for the number of spaces used to create a tab. Sometimes, in the case of a word processor, the font used dictates the number of spaces. In other words, realize that a tab can be set to any value, meaning a tab could be two, three, four, six, seven, or more spaces.
A tab is only one character. In other words, when you press Tab, it's not creating several spaces in a row.
In word processors like Google Docs and Microsoft Word, the tab length can be adjusted with the tab stops.
Should I use tabs or spaces for indenting?
Generally, we recommend using the Tab key to create indentation because it's quicker, less prone to errors, and makes files smaller.
In computer programming or creating a code block in a program, both tabs and spaces are valid for indentation. Some programmers swear by tabs, and others by spaces. Our best advice is to follow the standard set by either the original programmer or the company creating the program. If you are accustomed to spaces or tabs, you can convert one into another in many IDEs (integrated development environments). However, make sure you convert it back to the original standard after making changes.
Matching a tab character in a regular expression
When working with a regular expression, a tab is matched with the "\t" metacharacter or escape sequence with many programming languages. For example, with the Perl code below, if the $example variable contains any tab characters, the script prints "I found a tab!" when it is run. You can also use "\s" to find any whitespace, which means tabs or spaces would be found.
if ($example =~ /\t/) {
print "I found a tab!";
} if ($example =~ /\s/) {
print "I found white space!";
}