Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JavaScript Replace All Occurrences of a Substring in a String</title> </head> <body> <script> var str = "Color red looks brighter than color blue."; var result = str.replace(/color/ig, "paint"); document.write(result); // 0utputs: paint red looks brighter than paint blue. </script> </body> </html>