string method and regular expresions

<!doctype html>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>01 exam</title>
    <link rel="stylesheet" type="text/css" href="01 exam.css">
</head>
<body>

<h2>JavaScript String Methods</h2>

<p>Replace "Microsoft" with "W3Schools" in the paragraph below:</p>

<button onclick="myFunction()">Try it</button>

<p id="demo">paul,paula,pauline,panl,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>
原文地址:https://www.cnblogs.com/CheeseIce/p/9832414.html