Tell us what’s happening:
Two part question.
This challenge felt like a real tricky one. Especially since the last few were using capture groups
() in the regex and
,replacetext in a
So seeing the answers
/^\s*|\s*$/g threw me off. If we’re trying to take it out why do we not have to capture it in the
(). I tested it out and it works whether it’s in that format or this.
Second, with the last line, with the empty quotations
hello.replace(wsRegex, “”) why does leaving them empty result in
hello = " Hello, World! "; becoming “Hello, World!” without the spaces at beginning and end.
Thanks for the clarification. This one stumped me and even the answer didn’t make the concept feel a whole lot clearer.
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)
Your browser information:
User Agent is:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36.
Challenge: Remove Whitespace from Start and End
Link to the challenge: