Home  >  Article  >  Web Front-end  >  What is the JavaScript RegExp to find any alternative text?

What is the JavaScript RegExp to find any alternative text?

WBOY
WBOYforward
2023-08-20 23:51:02843browse

找到任何替代文本的JavaScript RegExp是什么?

To match any of the specified alternatives, please follow the pattern given below −

(foo|bar|baz)

Example

You can try running the following code to find any alternative text −

<html>
   <head>
      <title>JavaScript Regular Expression</title>
   </head>
   <body>
      <script>
         var myStr = "one,one,one, two, three, four, four";
         var reg = /(one|two|three)/g;
         var match = myStr.match(reg);

         document.write(match);
      </script>
   </body>
</html>

The above is the detailed content of What is the JavaScript RegExp to find any alternative text?. 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