Ad
  • Custom User Avatar
  • Custom User Avatar

    argh, I forgot about the + on regExp, I just used a filter to remove the extra spaces xd

  • Custom User Avatar

    "Yay, finally i found a single line regex magicfuckery solution like others too!!". compares with other solutions Oh... Well, anyways.

    Mine was so complicated simply because i replaced every single WUB with 1 space, ending up with so 3-4 spaces on recurring WUBs. So I had to handle that.

    All i needed was a single "+" on my regex, that's pretty smart. Slowly learning regex, it's fascinating.

  • 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

  • Custom User Avatar

    ^ CORRECTIONS AND TO BE MORE SPECIFIC:
    The + means to match whatever is infront of it 1 or more times**

    Then you have the astric * (which is not included but important to differentiate from the plus) it matches whatever is infront of it from 0 or more times.

    And finally g the global tells regex to not stop after the first match but continue and look for more matches

  • Custom User Avatar

    This was a great exercise to start to really dip my toes into regex and play around with some stuff. I am glad I got the same result here!

  • Custom User Avatar

    man thats very clever, gg

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    I'm curious on all these .repalce() answers does the .trim() have to loop over the string a second time? I wonder if there is a way to get it in one pass?

  • Default User Avatar

    Nice, very short code.
    But, it works!

  • Default User Avatar

    i dont even know why i cant think like this lol

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    I think the + says to match whatever comes in front of it as many times in a row as possible. so (WUB)+ means match WUB, WUBWUB, WUBWUBWUB, etc. The g at the end means match globally, or match as many times as possible (instead of stopping after the first match).

  • Custom User Avatar

    Tried that and gave me error, went for internet to some weird solution

  • Loading more items...