Perform a global, case-insensitive replacement: - Javascript RegExp

Javascript examples for RegExp:Modifier

Description

Perform a global, case-insensitive replacement:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<p id="demo">Blue blue BlUE .</p>

<button onclick="myFunction()">Test</button>

<script>
function myFunction() {//from w w w . j a  v a2 s. c o m
    var str = document.getElementById("demo").innerHTML;
    var res = str.replace(/blue/gi, "red");
    document.getElementById("demo").innerHTML = res;
}
</script>

</body>
</html>

Related Tutorials