Regular Expressions - Remove Whitespace from Start and End

Tell us what’s happening:
Describe your issue in detail here.

Hey, so I understand the solution when I click on “Get a Hint”, but I am curious why this solution won’t work for this particular question. It seems like there is an extra whitespace after “Hello, World!”, but I am curious why this happens.

Your code so far

let hello = "   Hello, World!  ";
let wsRegex = /^(\s+)(.+)(\s+)$/; // Change this line
let result = hello.replace(wsRegex, '$2'); // 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/103.0.0.0 Safari/537.36

Challenge: Regular Expressions - Remove Whitespace from Start and End

Link to the challenge:

Toss the regular expression up top and " Hello, World! " in the bottom and see if you can find out what is going on.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.