Regular Expressions - Remove Whitespace from Start and End

Tell us what’s happening:
I just don’t understand the solution I saw while trying to get a hint. Can I get more explanations pls

Your code so far

let hello = "   Hello, World!  ";
let wsRegex = /change/; // Change this line
let result = hello; // 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:

  • define the regular expression to move the blank spaces around the string assigned to the variable ‘hello’:
You can use the following:
^ means the beginning of the string
\s means whitespace characters in regex
+ means 1 or more 
| means OR (match the left side or the right side)
the g means "global" (match as many times as you can)
$ means the end of a string
....browse a bit to find out more about Regex...

So, the first part of the value assigned to your second variable in his challenge should look like:

/^\s+| ...try to define the second part by yourself

Then, apply the ‘replace’ method on the first variable ‘hello’ and assign the result to the variable ‘result’:

let result = hello.replace(secondVariable, "");

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