What Is Javascript RegExp \0 Metacharacter In Javascript

admin_img Posted By Bajarangi soft , Posted On 16-09-2020

RegExp \0 metacharacter is used to find NULL character.\0 returns the position where the NULL character was found. If no match is found, it returns -1

JS_RegExp_Metacharacter

 

  1. The RegExp \0 Metacharacter in JavaScript is used to find the NULL character.
  2. \0 returns the position where the NUL character was found. If no match is found, it returns -1.

Syntax:
/\0/  

or 

new RegExp("\\0")

Search for a NUL character in a string:
 
function myFunction() {
    var str = "Visit W3Schools.\0Learn JavaScript.";
    var patt1 = /\0/;
    var result = str.search(patt1);
    document.getElementById("demo").innerHTML = result;
}


Complete Code of JavaScript  RegExp \0 Metacharacter.
<html>
<head>
    <title>JavaScript | RegExp \0 Metacharacter</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
</head>
<body>
<div class="container ">
    <div class="text-center">
        <h1>JavaScript | RegExp \0 Metacharacter</h1>
    </div>
    <br>
    <div class="well">
        <h3>Click the button to returns the position or returns -1.</h3>

        <button class="btn btn-primary" onclick="myFunction()">Press it</button>
        <br>
        <h1 id="demo"></h1>

        <script>
            function myFunction() {
                var str = "Learn More JavaScript.\0 From Bajarangisoft.";
                var patt1 = /\0/;
                var result = str.search(patt1);
                document.getElementById("demo").innerHTML = result;
            }
        </script>
    </div>
</div>
</body>
</html>

Related Post