I can’t. I need to use regex. Also this condition only works with this challenge and string so any another string will not work which is not the main purpose of this challenge…
OG, you’re right. Your current regex doesn’t work because it’s removing EVERY whitespace character from the string. But that’s not what you want. You want to remove all whitespace from the beginning and end of the string only.
Here are some links that I found helpful while doing this challenge. Read them and I suspect you’ll figure out how to write the appropriate regex:
Passed that challenge after I came to know that , and ! are not alphanumeric. Anyway here’s the solution.
let hello = " Hello, World! ";
let wsRegex = /^\s+(\w+,\s\w+!)\s+$/; // Change this line
let result = hello.replace(wsRegex, ‘$1’); // Change this line
let hello = " Hello, World! ";
let wsRegexmatch = /\w+,\s\w+!/g; // Change this line
let match = hello.match(wsRegexmatch);
let result = hello.replace(hello,match);
The \w will always mean “one of letters, numbers, underscore”
even if you add +, nowhere you have that exact pattern, as there is punctuation extra that your regex doesn’t contemplate