let hello = " Hello, World! ";
let wsRegex = /Hello, World!/; // Change this line
let replaceText = " "; // Change this line
let result = hello.replace(wsRegex, replaceText);
So you’re looking to do two things with the regular expression: find whitespaceat the beginning of the string and/or whitespaceat 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.
let hello = " Hello, World! ";
let wsRegex = "/^\s+|\s+$/g"; // Change this line
let replaceText = ""; // Change this line
let result = hello.replace(wsRegex, replaceText);
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