Ad
  • Custom User Avatar

    (+) operator doing that job
    eg:"WUBWUBWUBWUB".replace(/(WUB)/g) is equal to " " so in this case we get four empty spaces. because it replace every WUB into empty string tha't why we are using + symbol it means it check minimum one 'WUB' matches.
    eg1:"WUB".replace(/(WUB)+/g) is equal to " ",
    eg2:"WUBWUB".replace(/(WUB)+/g) is equal to " ",
    eg3:"WUBWUBWUBWUB".replace(/(WUB)+/g) is equal to " ".in this case there are fout 'WUB' substrings are here so it replace that string into one empty string

  • Default User Avatar

    How does this code remove the multiple spaces? I can only understand how it replaces the WUBs with a space each time, not how it accounts for the potential multiple spaces