Regular Expressions - Remove Whitespace from Start and End

Tell us what’s happening:
Describe your issue in detail here.
is it right my code is still working but don’t know is it right or not!

Your code so far

let hello = "   Hello, World!  ";
let wsRegex = /(hello,)\s(world!)/i; // Change this line
let result = hello.match(wsRegex)[0]; // Change this line

Your browser information:

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

Challenge: Regular Expressions - Remove Whitespace from Start and End

Link to the challenge:

Your regular expression should be generic so that it could potentially work with any string, not just the string in the hello variable. Remember, you are trying to match the white space at the very beginning and very end of the string, not the actual text in the string.

Also, when setting the result variable, it’s not enough to just do a match on the expression, you want to remove the white space from the beginning and end of the string. In other words, you can think of it as wanting to replace that white space with nothing.


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