哪个 JavaScript RegExp 可以查找任何替代文本?

htmljavascriptprogramming scripts更新于 2024/8/19 6:44:00

要匹配任何指定的替代文本,请遵循下面给出的模式 −

(foo|bar|baz)

示例

您可以尝试运行以下代码来查找任何替代文本 −

<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>

相关文章