Remove Whitespace from Start and End (HELP)

What went wrong? Am I just matching and not removing anything? I don’t know if the proper method is being used but I decided to go with match(). Thanks!


let hello = "   Hello, World!  ";
let wsRegex = /$\s+\w+\s+$/; // Change this line
let result = hello.match(wsRegex); // Change this line
console.log(hello)

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36.

Challenge: Remove Whitespace from Start and End

Link to the challenge:

1 Like

Run this line instead:

console.log('hi', result, 'hi')

You will be able to solve it :slight_smile:

Edit

You are console logging hello (and not result)

Edit 2

Wrote a funny solution, but with the hope that you will improve it:

let hello = "   Hello, World!  ";
let wsRegex = /H.*!/; // Improve this line!! Don't be lazy!
let result = hello.match(wsRegex); 
console.log("hi", result, "hi")
1 Like

So the hello.match(wsRegex); line is correct? I knew it must have been something with the wsRegex line.

Yes, that line is fine…!

1 Like

So I completed it! I just consoled the result as you said and it showed me what the string looked like live and I just inserted the proper characters. Here was the solution:

let hello = "   Hello, World!  ";
let wsRegex = /\S*\w+.\s\w+./; // Change this line
let result = hello.match(wsRegex); // Change this line
console.log(result)

That was much appreciated :slight_smile:

nice! regex it’s difficult but pays well

good luck for the next ones

1 Like