I’m having trouble understanding why my solution isn’t accepted. My console log gives the result “Hello, World!” and it passes when I test it on regexr.com too. It seems I approached the problem in the opposite way as it was intended to be solved, but is there some larger issue with my code that I’m just not seeing?
let hello = " Hello, World! "; let wsRegex = /(\w+\W)(\s)(\w+\W)/; let result = hello.replace(wsRegex, ""); 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/184.108.40.206 Safari/537.36
Challenge: Regular Expressions - Remove Whitespace from Start and End
Link to the challenge: