Tell us what’s happening:
As shown in my code, I set my regex as /[^\s].+[^\s]/ to omit whitespace before and after any letters. I used let result = console.log(hello.match(wsRegex)); to check it and this was the outpput
[ ‘Hello, World!’,
input: ’ Hello, World! ',
groups: undefined ]
According to “[ ‘Hello, World!’,” this seems to imply the my regex did in fact remove the whitespace before and after Hello, World! but for some reason the requirement "
result should be equal to the string
Hello, World!" is not fulfilled. Please let me know where I went wrong with understanding the instructions or my attempt.
Your code so far
let hello = " Hello, World! "; let wsRegex = /[^\s].+[^\s]/; // Change this line let result = console.log(hello.match(wsRegex)); // Change this line
Your browser information:
User Agent is:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.61 Safari/537.36
Challenge: Remove Whitespace from Start and End
Link to the challenge: