Match any string with p at the beginning of it.

HTMLJavascriptProgramming Scripts

To match any string with p at the beginning of it with JavaScript RegExp, use the ^p Quantifier −

Example

<html>
   <head>
      <title>JavaScript Regular Expression</title>
   </head>
   <body>
      <script>
         var myStr = "Welcome to our website. We Learners!";
         var reg = /^We/g;
         var match = myStr.match(reg);
         
         document.write(match);
      </script>
   </body>
</html>
raja
Published on 26-Feb-2018 08:21:26
Advertisements