JavaScript RegExp \t Metacharacter

Last Updated : 5 Aug, 2025

The RegExp \t Metacharacter in JavaScript is used to find the tab character. If it is found it returns the position else it returns -1. 

JavaScript
let str = "GFG\t@_123_$";
let regex = /\t/;
let match = str.search(regex);
if (match == -1) {
  console.log("No tab character present. ");
} else {
  console.log("Index of tab character: " + match);
}

Output
Index of tab character: 3

Syntax: 

/\t/ 
// or
new RegExp("\\t")

Example 1: Searches for the tab character in the string. 

JavaScript
let str = "GeeksforGeeks@_123_$";
let regex = /\t/;
let match = str.search(regex);
if (match == -1) {
  console.log("No tab character present. ");
} else {
  console.log("Index of tab character: " + match);
}

Output
No tab character present. 

 Example 2: Searches the position of the tab character in the string. 

JavaScript
let str = "123ge\teky456";
let regex= new RegExp("\\t");
let match = str.search(regex);

console.log(" Index of tab character: " + match);
Comment