How to replace all occurrences of a string?
Loading
How to replace all occurrences of a string?
Regex.Replace(“you want to be in Microsoft because you deserve Good Life in this world”,@”[/you/]”,”i”);
Hi,
You can use string.replace() method with regular expression of global (g means replace it globally).
let str = "Mr blue has a blue house and a blue car";str.replace(/blue/g, "red");//Output: Mr red has a red house and a red car.
If we need to replace “Microsoft” with “Google” we can do it by:str.replace("Microsoft", "Google");