<!DOCTYPE html>
<html>
<body>
<p>The exec() method returns the matched text if it finds a match, otherwise it returns null.</p>
<p>Click the button to search a string for the character "e".</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var str = "The best things in life are free";
var patt = new RegExp("e");
var res = patt.exec(str);
document.getElementById("demo").innerHTML = res;
}
</script>
</body>
</html>