Regular Expressions - Remove Whitespace from Start and End

Tell us what’s happening:
Describe your issue in detail here.
I am asking for help with this code. I expect it to work out but I don’t know where there is a mistake.
Your code so far

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

Your browser information:

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

Challenge: Regular Expressions - Remove Whitespace from Start and End

Link to the challenge:

there are two occurrences of ^ symbol. This means that the regular expression matches one or more whitespace characters at the beginning of the string (^\s+ ) OR (| ) one or more whitespace characters at the end of the string (^\s+$ ).
you need only one at the beginning …

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