Regular Expressions - Remove Whitespace from Start and End

Tell us what’s happening:
Describe your issue in detail here.

Your code so far
My code works so I don’t know why it is rejected. How might I remove whitespace rather than not select it? is that the question?

let hello = "   Hello, World!  ";
let wsRegex = /[\S].+\S/g; // Change this line
let result = hello.match(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/112.0.0.0 Safari/537.36 Edg/112.0.1722.64

Challenge: Regular Expressions - Remove Whitespace from Start and End

Link to the challenge:

The .match is going to return an array of all patterns that match. In your scenario, it will return:

[ 'Hello, World!' ]

How can you access the first index of the array and set the value of the result to that?

I am not sure what you are saying. However in the end I got it as the problem was getting a replace in the equation.

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