Could anyone explain the /^\s+|\s+$/g in detail
I am trying to understand the solution but for some reason I just cannot wrap my head around this one. I would like to know how does the code /^\s+|\s+$/g selects whitespace.
Your code so far
let hello = " Hello, World! ";
let wsRegex = /^\s+|\s+$/g; // Change this line
let result = hello.replace(wsRegex,""); // Change this line
console.log(result.split(''))
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36
Challenge: Remove Whitespace from Start and End
Link to the challenge: