首页 > 技术文章 > web-正则表达式

nsgbdzm 2018-11-17 11:37 原文

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Try it</button>
<p id="demo">Paul PAULA paula paul paul</p>
<script>
function myFunction() {
    var str = document.getElementById("demo").innerHTML;
    var txt = str.replace(/\bpaul\b/g,"atm");
    document.getElementById("demo").innerHTML = txt;
}
</script>
</body>
</html>
 
 

推荐阅读