How to replace string using JavaScript RegExp?

JavascriptWeb DevelopmentFront End Technology

To replace a string using RegExp in JavaScript, use the string replace() method.

Example

You can try to run the following code to replace a string using JavaScript RegExp −

<html>
   <head>
      <script>
         var str = "Welcome to Tutorialspoint";
         document.write(str);
         var res = str.replace(/tutorialspoint/i,"Qries");
         document.write("<br>"+res);
      </script>
   </head>
   <body>
   </body>
</html>
raja
Published on 23-Feb-2018 06:41:20
Advertisements