In the case of this challenge, you don’t need to worry about anything except for the beginning and end of the string. You’re looking for two things:
Does the string start with one or more instances of white space?
Does the string end with one or more instances of white space?
If yes, we want to remove that whitepace, and the way to remove whitespace is to replace it with an empty string (’’).
All non-whitespace characters are irrelevant.
Knowing this, you need to make changes to your replace function and your RegEx.
Remember, your RegEx should match whitespace at the start or end(hint hint with RegEx operators than can mean “or”) . Nothing else matters in the string. You may need to use at least one flag for this.
The first time I tried, I thought like that too. My code at first was like this:
let hello = " Hello, World! ";
let wsRegex = /(^\s*)(\s*$)/;
let result = hello.replace(wsRegex, ''''); /
But that code did not work. Used the website regex101.com or I think that was the name, but it kept saying no matches. I also changed the replace to instead of having 4 of this => ‘’ , to have only two. Also tried taking the parentheses out of the let wsRegex, etc. But it never worked.