Match any string containing a sequence of N p's


To match any string containing a sequence of N p’s with JavaScript RegExp, use the p{N} Quantifier.

Example

You can try to run the following code to match any string containing a sequence of N p’s −

<html>
   <head>
      <title>JavaScript Regular Expression</title>
   </head>

   <body>
      <script>
         var myStr = "Welcome 1, 100, 10000, 1000";
         var reg = /\d{3}/g;
         var match = myStr.match(reg);
         
         document.write(match);
      </script>
   </body>
</html>

Updated on: 23-Jun-2020

93 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements