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);
Updated on 23-Jun-2020 07:29:36