A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/javascript/javascript-regexp-0-metacharacter/ below:

JavaScript RegExp \0 Metacharacter - GeeksforGeeks

JavaScript RegExp \0 Metacharacter

Last Updated : 11 Jul, 2025

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

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

Output
Index of Null character: 7
Syntax:  
/\0/ 

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

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

Output
No Null characters present. 

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

JavaScript
let str = "123ge\0eky456";
let regex = new RegExp("\\0");
let match = str.search(regex);
console.log(" Index of NULL character: " + match);

Output
 Index of NULL character: 5
Advantage of using RegExp \0 Metacharacter Recommended Links:

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4