Regular expressions g:- genius student


The g modifier is used to perform a global match (find all matches rather than stopping after the first match).
Code:-

<!DOCTYPE html>
<html>

<head>
 <meta name="viewport" content="width=device-width, initial-scale=1">
</head>

<body>
 <h1>Regular Expression g</h1>

 <button onclick="fun_regexgno()">No g Regular Expression</button>

 <button onclick="fun_regexg()">g Regular Expression</button>

 <script>
  var str = "This is my apps";

  //g=> find all matches
  function fun_regexg()
  {

   alert(str.replace(/s/g, "#"));
  }

  //without using 'g'
  function fun_regexgno()
  {
   alert(str.replace(/s/, "#"));

  }
 </script>

</body>

</html>
Regular expressions g:- genius student Regular expressions g:- genius student Reviewed by Network security on October 27, 2019 Rating: 5

No comments:

Useful Information

Powered by Blogger.