Rajanikant Hawaldar
How to replace all occurrences of a string?

How to replace all occurrences of a string?

By Rajanikant Hawaldar in JavaScript on Oct 10 2020
  • sunny sharma
    Aug, 2021 22

    Regex.Replace(“you want to be in Microsoft because you deserve Good Life in this world”,@”[/you/]”,”i”);

    • 0
  • Ganesan C
    Aug, 2021 16

    Hi,

    You can use string.replace() method with regular expression of global (g means replace it globally).

    1. let str = "Mr blue has a blue house and a blue car";
    2. str.replace(/blue/g, "red");
    3. //Output: Mr red has a red house and a red car.

    • 0
  • Salman Beg
    Dec, 2020 18

    Hey. You need to use replace method. Check this video, https://youtu.be/DNiRjTaly4A

    • 0
  • Rajan M
    Oct, 2020 30
  • Kokul Jose
    Oct, 2020 15

    If we need to replace “Microsoft” with “Google” we can do it by:
    str.replace("Microsoft", "Google");

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS