Regular Expressions - Remove Whitespace from Start and End | Simpler solution?

Hello!

I’ve found solution for Regular Expressions - Remove Whitespace from Start and End Challenge which I think is a little simpler than what is present as Solution in Guide Page.

I’ve checked it with multiple words, devided by multiple whitespaces and I think it works as it should. Am i right or am I missing something? Does .replace() has any kind of adventage in that case?

FreeCodeCamp proposed solution:

let hello = "   Hello, World!  ";
let wsRegex = /^\s+|\s+$/g; // Change this line
let result = hello.replace(wsRegex, ""); // Change this line

My solution:

let hello = "   Hello, World!  ";
let wsRegex = /\S+.*\S+/; // Change this line
let result = hello.match(wsRegex)[0]; // Change this line

Thank you in advance for you comments!

Fine! I follow the same trail using the array properties. It works, but checking the FCC solution, I figure that this challenge is to be solved using the resources of the previous lessons on the module. Hence, the use of replace. Which never occurred to me either! Cheers.