Remove Whitespace from Start and End: Question on Alternation Expression

In the " Remove Whitespace from Start and End" challenge, you must use the alternation expression | in order for the regex to work:
/^\s+|\s+$/g;

How come /^\s+\s+$/g; without the alternation expression not work? What is the alternation expression truly doing? How is it helping match the white space at the start and end?

This expression translates to “At the start of a line, one or more whitespace characters immediately followed by one or more whitespace characters and then the end of the line.”