Regular Expressions - Remove Whitespace from Start and End

Tell us what’s happening:
For some reason this code fails the test “result should be equal to the string Hello, World!”. Passing result into console.log gives me Hello, World! as expected, and typeof result even gives me a string. What am I doing wrong here?

Your code so far

let hello = "   Hello, World!  ";
let wsRegex = /^(\s+)(.+)(\s+)$/; // Change this line
let result = hello.replace(wsRegex, '$2'); // Change this line

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0

Challenge: Regular Expressions - Remove Whitespace from Start and End

Link to the challenge:

Try this:

console.log(`[${result}]`);

Hello mattes!

I just finished my Regex but it doesn’t go thought.

This is my code:

let hello = " Hello, World! “;
let wsRegex = hello.replace(/\s+/,”") // Change this line
let result = wsRegex; // Change this line

console.log(result);

Hello, World!

// Why is not working? I also checked the answer and I put it in there but it did not work with the answer lol.

Can anybody help me?

Thanks!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.