Im curious as to why this regex dosen’t work, it feels like it should.
let wsRegex = /^(\s+)$/g;
let result = hello.replace(wsRegex, “”);
//returns " Hello, World! "
im trying to get it to search the beginning and the end. i’d kind of expect it to have gotten at least the first side as /^(\s+)/g does - trying to avoid the alternator as i dont really understand why its necessary and think understanding this solves both my problems. Thanks.
let hello = " Hello, World! "; let wsRegex = /^(\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/84.0.4147.89 Safari/537.36.
Challenge: Remove Whitespace from Start and End
Link to the challenge: