Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



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

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Java Coder
JavaScript regex exec() method for text match.
2 Answer(s)      2 years and 6 months ago
Posted in : JavaScript Questions


JavaScript regex exec() method for text match.


Advertisement
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 Tutorials/Questions & Answers:
 

 

 

DMCA.com