1. 程式人生 > >正則表達式替換

正則表達式替換

UNC .get cli asc txt document ring exp oct

代碼如下:

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Regular Expressions</h2>

<p>正則表達式把所有Paul替換成Ringo:Paul Puala Pualine paul Paul
</p>

<button onclick="myFunction()">瘋狂點我</button>

<p id="demo">Paul Puala Pualine paul Paul!</p>

<script>
function myFunction() {
var str = document.getElementById("demo").innerHTML;
var txt = str.replace(/Paul/g,"Ringo");
document.getElementById("demo").innerHTML = txt;
}
</script>

</body>
</html>

正則表達式替換