How to select whitespace at the end

*Tell us what’s happening:
Maybe someone can explain what is going on but I think that the + symbol takes the remainder of what happens after the match.
For example: \s+$
Doesn’t this mean that you are looking for the ‘space’ at the end because of the $ symbol, but why do you need the + at the end if the space is at the end with nothing following it?

Your code so far

let hello = "   Hello, World!  ";
let wsRegex = /change/; // Change this line
let result = hello; // 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/81.0.4044.138 Safari/537.36.

Challenge: Remove Whitespace from Start and End

Link to the challenge:

The \s will match one single space, \s+ instead means one or more.
Notice that you have many spaces at the end of the string and you want to remove all of them, not just one.

The + (one or more) means match it one or more times, that means its going to match it until there is no more space

According to the instructions, we just want to remove the beginning and ending space. In this example, there is only one ‘space’ that would qualify for the \s$, right?

what example?

the challenge has this string: " Hello, World! "

"   Hello, World!  ";
 |||             ||
 123             12

there are three spaces to remove at the beginning and 2 at the end.
with just \s$ you are just selecting the number 2 at the end of the string

1 Like

You want to select one or more white spaces from the text, and delete them

ohhh, I see. I didn’t realize there were multiple spaces at the beginning and the end. That makes much more sense. Thanks for the clarification!