<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>RegExp</title>
</head>
<body>
<script>
var reg=new RegExp("Paul");
var stringObj="Paul Paula Pauline";
var newstr=stringObj.replace(reg,"Ringo");
alert(newstr);
</script>
</body>
</html>
運行結果如圖所示:html