Home Answers Viewqa JavaScriptQuestions JavaScript regex exec() method for text match.

 
 


Java Coder
JavaScript regex exec() method for text match.
2 Answer(s)      a year ago
Posted in : JavaScript Questions

JavaScript regex exec() method for text match.

View Answers

May 12, 2012 at 1:50 PM


<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>

May 12, 2012 at 1:50 PM


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.









Related Pages:

Ask Questions?

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.