Confused from `^` as it negates or selects the start of a line

Tell us what’s happening:
I am confused from the cases where the ^ negates and the other when it selects a word at the beginning of a line

Your code so far

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

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36.

Challenge: Remove Whitespace from Start and End

Link to the challenge:

It depends on the context it is used in. This page explains it quite well:

1 Like

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