首页 > 文章列表 > 匹配任何包含零个或多个p的字符串

匹配任何包含零个或多个p的字符串

字符串 匹配 包含
194 2023-09-12

要使用 JavaScript RegExp 匹配任何包含零个或多个 p 的字符串,请使用 p* 量词。

示例

您可以尝试运行以下代码来匹配包含零个或多个 p 的任何字符串。这里,p 被认为是出现的次数 -

<html>
   <head>
      <title>JavaScript Regular Expression</title>
   </head>
   <body>
      <script>
         var myStr = "Welcome! Wweeeelcome to our website!";
         var reg = /el*/g;
         var match = myStr.match(reg);

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