将Paul替换为ringo
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>RegExp</title>
</head>
<script>
function strreplace(){
var str=document.getElementById("str").value;
var newstr=str.replace(/paul/g,"Ringo");
document.getElementById("demo").innerHTML = newstr;
}
</script> <body>
paul like Spaul Paul paul
<br><br><br><input type="text" name="str" id="str">
<input type="button" value="替换" onclick="strreplace()">
<br><br>替换后:<p id="demo"></p>
</body>