What is the role of exec method in JavaScript RegExp?

HTMLJavascriptProgramming Scripts

The exec() method in JavaScript searches for a string with a pattern. Returns NULL, if no match is found, else returns the text you searched for.


You can try to run the following code to learn how to work with exec() method in JavaScript Regular Expression −

      <title>JavaScript Regular Expressions</title>
         var myStr = "Welcome to our website! Welcome to Tutorialspoint!";
         var res = /t/.exec(myStr);
Published on 26-Feb-2018 10:37:15