Để thay thế chuỗi bằng RegExp trong JavaScript, sử dụng phương thức replace() của chuỗi.
Ví dụ
<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>