JavaScript RegExp Tab Metacharacter (\t)

Beginner
6 min read
Updated: Oct 2026
3 examples
Live preview

What Is \t?

\t matches one horizontal tab character (U+0009). Use it to detect tabs, parse TSV columns, or convert tabs to spaces—without matching regular space characters.

Remember
\t  → horizontal tab (U+0009)
\s  → any whitespace (includes \t)
\v  → vertical tab (different character)

/\t/.test("hello")      → false
/\t/.test("a\tb")       → true
"a\tb".replace(/\t/g, " ") → "a b"
UsePrefer
Detect a tab/\t/
Split TSV columnsrow.split(/\t/)
Tabs → spacesstr.replace(/\t/g, " ")
Any whitespace\s

How to Use \t

Treat the tab as a precise delimiter—not as “a few spaces.”

  1. Insert tabs in strings with "\t".
  2. Use /\t/ with test, split, or replace.
  3. Add the g flag when every tab must be replaced.
  4. Prefer \t over \s when spaces should stay untouched.
PieceRequired?Role
\t in the patternYesMatch one horizontal tab
String escapeFor demos"\t" inserts a tab into a string
g flagOptionalFind or replace every tab
vs \s—\s also matches space and newline

Pseudocode

Pseudocode
pattern has "\t"
read next character ch from the string

if ch.codePoint === 9:   // horizontal tab
    accept match
else:
    fail this path

common actions:
  test(str)              → true if any tab exists
  split(/\t/)            → TSV columns
  replace(/\t/g, " ")    → convert tabs to spaces

Cheat Sheet

Keep these facts handy when working with tabs and TSV data.

TopicDetail
CharacterHorizontal tab — U+0009 (code point 9)
Detect/\t/.test(str)
Split columnsrow.split(/\t/)
Replacestr.replace(/\t/g, " ")
Whitespace?Yes — included in \s
Not the same asSpaces · \v vertical tab
StandardES3+ (universal)

Live Preview

Run common \t operations on sample strings that contain tabs.

Browser demo of the RegExp \t tab escape — same ideas as the examples below.

Result
text = "hello"
/\t/.test(text)
→ false

/* no tab character present */

JavaScript Examples

Short, copy-ready snippets. Open DevTools Console, or use Try It Yourself for a live editor.

Example 1 — Detect a Tab

Return true only when a real tab character is present—not a space.

JavaScript
console.log(/\t/.test("hello"));       // false
console.log(/\t/.test("a\tb"));        // true
console.log(/\t/.test("hello world")); // false
Try It Yourself

How It Works

  1. Plain text. "hello" has no tab → false.
  2. Insert a tab. "\t" embeds a real U+0009 character.
  3. Pattern matches. /\t/ finds that character anywhere in the string.
  4. Spaces do not count. "hello world" has a space, not a tab → false.

Example 2 — Split a TSV Row

Break a tab-separated line into columns.

JavaScript
const row = "Ada\t36\tLondon";

console.log(row.split(/\t/));
// ["Ada", "36", "London"]
Try It Yourself

How It Works

  1. TSV row. Fields are separated by tab characters, not commas.
  2. Split on \t. Each tab becomes a column boundary.
  3. Spaces stay inside fields. Only tabs cut the string.
  4. Result. Three clean column values.

Example 3 — Replace Tabs with Spaces

Convert every tab into a single space for display or plain-text export.

JavaScript
const indented = "line1\t\tline2";

console.log(indented.replace(/\t/g, " "));
// "line1  line2"

console.log(indented.charCodeAt(5)); // 9 (tab)
Try It Yourself

How It Works

  1. Two tabs. Between line1 and line2 sit two tab characters.
  2. Global replace. /\t/g finds every tab.
  3. One space each. Each tab becomes a single space (two tabs → two spaces).
  4. Confirm with code. charCodeAt returns 9 for a tab.

Edge Cases & Pitfalls

Check these before relying on \t in real projects.

spaces

A tab is not “several spaces”

Visually a tab may look wide, but it is one character. /\t/ never matches a run of space characters.

tsv

Double tabs mean empty columns

"a\t\tb".split(/\t/) yields ["a", "", "b"]. Empty fields are real TSV values.

scope

\s is broader than \t

Use \s when any whitespace is fine. Use \t when spaces and newlines must stay.

vs

\t ≠ \v

Horizontal tab and vertical tab are different control characters. Do not mix them up.

Browser & Runtime Support

The \t tab escape is core regex syntax (ES3+) and works everywhere JavaScript runs.

✓ Baseline · ES3+

RegExp \t

Supported in every modern and legacy browser, plus all Node.js versions. No polyfill required.

100% Universal support
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
\t Excellent

Bottom line: Safe to use in any JavaScript environment. Prefer \t over \s when you need tab-only matching.

Performance Notes

ApproachCostBest for
/\t/.test(str)O(n)Quick “has tab?” checks
str.split(/\t/)O(n)Parsing TSV rows
str.replace(/\t/g, " ")O(n)Normalizing indentation

Single-character escapes are cheap. Prefer \s only when you intentionally want every whitespace type.

Key Takeaways

  • Role: \t matches one horizontal tab (U+0009).
  • TSV: split(/\t/) cuts columns without touching spaces.
  • Normalize: replace(/\t/g, " ") turns tabs into spaces.
  • Not spaces: a tab is one character; \s is broader.

One line: \t finds the horizontal tab — detect it, split TSV with split(/\t/), or convert tabs to spaces with replace.

Frequently Asked Questions

\t matches the horizontal tab character (HT, Unicode U+0009, ASCII 9). It is the single control character produced by the Tab key in most text editors.
No. A tab is one character with code point 9. It may look like several spaces when displayed, but regex matches exactly one tab—not a run of space characters.
Yes. Horizontal tab is included in the \s whitespace class along with space, newline, carriage return, form feed, and vertical tab.
Use split with a tab pattern: row.split(/\t/). For a full file, split lines first with /\n/, then split each line on /\t/.
\t is horizontal tab (same line, next tab stop). \v is vertical tab—a different, rarely used control character.
The \t escape is core regex syntax since ES3. It works in every browser and Node.js version.

Next: \uXXXX Unicode

Learn how Unicode escapes match specific characters by code point.

\uXXXX tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful