Remove Whitespace from Start and End help this

Remove Whitespace from Start and End help this
0

#1

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
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/67.0.3396.99 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/regular-expressions/remove-whitespace-from-start-and-end/


#2

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


#3

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


#4

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,"");
console.log(result);

#5

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