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>