ANSWER SPOILER! Remove Whitespace from Start and End

Hey guys, I did this /Hello, World[^\s$]/; and it passes the test check but the answer from FCC is: ```
let wsRegex = /^\s+|\s+$/g;

I would like to know if it's okay to answer this question the way I did, or if I should switch to the answer given by FCC. And if possible, can I get an explanation as to why?

Thank you so much, any help is appreciated!

**Your code so far**

```js

let hello = "   Hello, World!  ";
let wsRegex = /Hello, World[^\s$]/; // 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/70.0.3538.77 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/regular-expressions/remove-whitespace-from-start-and-end

Your answer is not ok. You’re handling only the " Hello, World! " string and the challenge asks you to handle every string:

Write a regex and use the appropriate string methods to remove whitespace at the beginning and end of strings.

Of course FCC could added more tests with different strings, and that will probably be a good thing, but nothing stop you from handling each test separately instead of creating an appropriate algorithm that handles all cases.

1 Like

Thank you man, I see my mistake now :slight_smile: