Home  >  Article  >  Web Front-end  >  How to match regular expression with string?

How to match regular expression with string?

WBOY
WBOYforward
2023-09-09 18:45:021527browse

How to match regular expression with string?

Use the match() method to match a regular expression against a string in JavaScript. You can try running the following code to match a regular expression -

Here are the parameters -

  • match ( param ) - the regular expression object.

Example

You can try running the following code to match a string with a regular expression -

<html>
   <head>
      <title>JavaScript String match() Method</title>
   </head>
   <body>
      <script>
         var str = "For more information, see Chapter 3.4.5.1";
         var re = /(chapter \d+(\.\d)*)/i;
         var found = str.match( re );
         
         document.write(found );
      </script>
   </body>
</html>

The above is the detailed content of How to match regular expression with string?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete