Regular Expressions: Remove Whitespace from Start and End problem

Here is the link: https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/regular-expressions/remove-whitespace-from-start-and-end/

Here is my code:

let hello = "   Hello, World!  ";
let wsRegex = /Hello, World!/; // Change this line
let replaceText = "  "; // Change this line
let result = hello.replace(wsRegex, replaceText);

It does not work. I get error:

result should equal to “Hello, World!”

Any ideas?

So you’re looking to do two things with the regular expression: find whitespace at the beginning of the string and/or whitespace at the end of the string. You want to write a regex that can do those two things. You aren’t looking for Hello, World.

Also, on the replacement text you have “ “ which would still leave some whitespace. You want the empty string “” instead.

Thanks for the reply.

So. I have this code now:

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

but I get error:

result should equal to “Hello, World!”

Any ideas?

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

Works For me

But i prefer this

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

But I keep getting error message: result should equal to “Hello, World!”

Your regex shouldn’t be in quotes

Thank you for your reply.