Hello everyone. I have been trying the following code so far to solve this challenge:
let hello = " Hello, World! ";
let wsRegex = /^\s*|\s*$/; // Change this line
let result = hello.replace(wsRegex,""); // Change this line
I have tried it also on jsbin.com and the result is “Hello, World!”, as expected. But on freeCodeCamp I pass two out of the three tests but the third says:
result should equal to “Hello, World!”. What am I doing wrong?
Thank you in advance.
The | is an OR operator
The g flag is needed to match all the spaces that are at the beginning OR at the end. Otherwise it would match only the first part of the regex, and the second part only if the first part doesn’t match anything