
JavaScript regex exec() method for text match.

<html>
<head>
<title> regex exec() for text matching</title>
<script type="text/javascript">
function validate() {
var name = document.getElementById("name").value;
var pattern = /Hello/;
if (pattern.exec(name)) {
alert("Pattern matched");
return true;
}
alert("Pattern is not matched in inputed String");
return false;
}
</script>
</head>
<body>
<h2>Matching pattern using exec()..</h2>
Enter any String :
<input type="text" name="name" id="name" />
<input type="submit" value="Check" onclick="validate();" />
</body>
</html>

exec() method searches content that matches to the pattern. If it finds the pattern return
array of list otherwise it return null. You can use g modifier for global match as /Hello/g ,
i is used for case insensitive matching and m is used for multiline matching.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.