/\0/
or
new RegExp("\\0")
function myFunction() {
var str = "Visit W3Schools.\0Learn JavaScript.";
var patt1 = /\0/;
var result = str.search(patt1);
document.getElementById("demo").innerHTML = result;
}
<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>