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> let str = "Color red looks brighter than color blue."; let result = str.replace(/color/ig, "paint"); document.write(result); // 0utputs: paint red looks brighter than paint blue. </script> </body> </html>