Isnt this /^(\s+)|(\s)$/ equal to /^\s+|\s+$/g

Tell us what’s happening:
Describe your issue in detail here.
Isnt this /^(\s+)|(\s+)$/ equal to this /^\s+|\s+$/g ?

I am asking because the problem doesn’t accept this /^(\s+)|(\s)$/ as the answer

Your code so far

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

Your browser information:

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

Challenge: Remove Whitespace from Start and End

Link to the challenge:

Yes, those are the same but I think your problem is that you forgot the global flag.

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