\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.
Treat the tab as a precise delimiter—not as “a few spaces.”
Insert tabs in strings with "\t".
Use /\t/ with test, split, or replace.
Add the g flag when every tab must be replaced.
Prefer \t over \s when spaces should stay untouched.
Piece
Required?
Role
\t in the pattern
Yes
Match one horizontal tab
String escape
For demos
"\t" inserts a tab into a string
g flag
Optional
Find 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
Reference
Cheat Sheet
Keep these facts handy when working with tabs and TSV data.
Topic
Detail
Character
Horizontal tab — U+0009 (code point 9)
Detect
/\t/.test(str)
Split columns
row.split(/\t/)
Replace
str.replace(/\t/g, " ")
Whitespace?
Yes — included in \s
Not the same as
Spaces · \v vertical tab
Standard
ES3+ (universal)
Try it
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 */
Code
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.
Two tabs. Between line1 and line2 sit two tab characters.
Global replace./\t/g finds every tab.
One space each. Each tab becomes a single space (two tabs → two spaces).
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.
Compatibility
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 ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
\tExcellent
Bottom line: Safe to use in any JavaScript environment. Prefer \t over \s when you need tab-only matching.
Analysis
Performance Notes
Approach
Cost
Best 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.
Remember
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.