How to use exec in JavaScript

This article describe about exec() Method in JavaScript.
  • 1739

exec() Method in JavaScript

This method is used to tests for a match in a string.

And returns null if doesn't fine otherwise return the matched text if it find a match.

Syntax

RegExpObject.exec(string)

 

Parameter Description
string Required. For search

Example

<!DOCTYPE html>

<html>

<body>

<script type="text/javascript">

    var str = "This is my first paragraph!";

    var pattern = /first/g;

    var res = pattern.exec(str);

    document.write("Returned value: " + res);

    patt = /dotnetheaven.com/g;

    res = patt.exec(str);

    document.write("<br />Returned value: " + res);

</script>

</body>

</html>

 

Output

 

pic2.jpg

You may also want to read these related articles Click here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

Categories

More Articles

© 2018 DotNetHeaven. All rights reserved.