Remove Whitespace from Start and End...Both cases in or

Tell us what’s happening:
/^\s+|\s+$/g is supposed to match and replace either ^\s+ or \s+$ …
But here, it’s matching and replacing both, Why ?

Your code so far

let hello = "   Hello, World!  ";
let wsRegex = /^\s+|\s+$/g; 
let result = hello.replace(wsRegex, "");


let some = "aapp"

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36.

Link to the challenge:

You have a global flag, that means it finds all matches

1 Like