Home > Web Front-end > HTML Tutorial > What is the role of the exec method in JavaScript RegExp?

What is the role of the exec method in JavaScript RegExp?

WBOY
Release: 2023-08-28 18:33:09
forward
826 people have browsed it

JavaScript RegExp中的exec方法的作用是什么?

The exec() method in JavaScript searches for a string with a pattern. If no match is found, NULL is returned, otherwise the text you searched for is returned.

Example

You can try running the following code to learn how to use the exec() method in JavaScript regular expressions -

<html>
   <head>
      <title>JavaScript Regular Expressions</title>
   </head>
   <body>
      <script>
         var myStr = "Welcome to our website! Welcome to Tutorialspoint!";
         var res = /t/.exec(myStr);
         document.write(res);
      </script>
   </body>
</html>
Copy after login

The above is the detailed content of What is the role of the exec method in JavaScript RegExp?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template