Remove Whitespace from Start and End ---

Tell us what’s happening:
Hello, why does this not work?

Your code so far


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

Challenge: Remove Whitespace from Start and End

Link to the challenge:

because you are missing the spaces at the beginning and end of string

you wrote /^(\w+) but there are no letters at the beginning of the string , and !$/ but there is not punctuation at the end of string, there are spaces

Yeah because I want it to not have any spaces eventually… one question in this case ($1 2) do these stand for only words?

those stands what you have inside the capture groups

your first capture group is (\w+) so $1 will be what’s matched by the capture group

your regex needs to match the pattern of the string tho, using this way the spaces should be matched, but not captured in the capture groups so that after when you use $1 the spaces are not placed in the new string

Thank you so much!!! you made it so much clearer