I’ve always found regex successful in blowing my head off. Anyways, finished the regex part of the course, and solved the last one (removing trailing spaces) by using two regex’s:
let hello = " Hello, World! "; let wsRegex = /^\s+/; // Change this line let anotherWsRegex = /\s+$/; let result = hello.replace(wsRegex, ""); // Change this line result = result.replace(anotherWsRegex, "");
I have no idea why something like
^\s+|\s+$ works in detecting the trailing spaces but the
replace method only removes the first match, i.e. in the beginning.
Any clarifications would be highly appreciated. Thanks.