Chrome Extension

Replace characters globally Javascript

//Case sensitive
var str = "Color is Green and green is a cold color";
var result = str.replace(/green/g, "blue");
//output - Color is Green and blue is a cold color

//Applly for case insensitive
var res = str.replace(/green/gi, "blue");
//output - Color is blue and blue is a cold colors

You can use .replace() function to replace characters with some other characters in javascript. Use 'g' with the string that needs to be replaced for case sensitive replacement and 'gi' for case insensitive replacement.

Search history ×