Remove Whitespace from Start and End help this

Tell us what’s happening:

Your code so far

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

Link to the challenge:

So, what’s happening? What else have you tried?

What did you expect to work that didn’t?

Noone’s going to try to help if we don’t know these things

is this part correct? I would have thought you want to search for space at the end like this:

I have tried this but I want fewer lines than this which I was not able to get

let hello = "   Hello, World!  ";
let wsRegex = /^(\s+)/g;
let result = hello.replace(wsRegex,"");
let wsRegex1 = /(\s+)$/g;
result = result.replace(wsRegex1,"");

You can chain the functions and put the regex directly in the functions, though there’s nothing wrong with a 4 line function

1 Like