<!DOCTYPE html>
<html>
<body>
<p>Do a global search, and test for "Hello" and "W3Schools" in a string:</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var str = "Hello world!";
//look for "Hello"
var patt = /Hello/g;
var result = patt.test(str);
//look for "W3Schools"
patt2 = /W3Schools/g;
result2 = patt2.test(str);
document.getElementById("demo").innerHTML = result + "<br>" + result2;
}
</script>
</body>
</html>