JavaScript \0 Metacharacter | RegEx Search Null Character

The JavaScript \0 metacharacter is used to find a null character in a string using JavaScript regular expression. For example:

HTML with JavaScript Code
<!DOCTYPE html>

  <p id="myPara"></p>

      let myString = "JavaScript is Fun.\0Is not it?";
      let pattern = /\0/;
      document.getElementById("myPara").innerHTML =;

Since the \0 is available at index number 18, therefore the above JavaScript code produces 18 as output.

Note: The search() method is used to search a substring (value) in a string using regular expression.

JavaScript Online Test

« Previous Tutorial Next Tutorial »

Liked this article? Share it!

Like/follow us on social media for updates!