Remove Whitespace from Start and End: when "or" means "and"

I needed a hint to crack this challenge.
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/regular-expressions/remove-whitespace-from-start-and-end

I was getting everything from before but not after until I added the g at the end. But then I was thinking: Why is this working at all? Doesn’t the | (pipe) mean “or” shouldn’t it take of from either the front OR the end?

Thanks for any insight.

You need to recall the string so it can remove the whitespaces

do you mean something like /a|b/?
the thing is that if you let it like that it will match or just the a or just the b
for example, if you have a word like barabba the regex like that will match only one letter. If you add the g it will match b, a, a, b, b, a
try using the match method and look at the resulting array - that is what the replace method will change

Exactly: /a | b/ means a or b. I thought if a matches it ignores b. So why does it return both a and b? Or does the g mean that it applies the a or b test to the whole string? I guess it must. Now I get it, arghh. Thx

BTW. What’s the trick to get monospace for excerpts when writing in this forum?

Now you got it.

To format code in the middle of regular text you can surround it with single backticks (not to be confused with apostrophes or single quotes). If you want to display a code segment, then you need to start with a line of only 3 backticks, then your code, then a line of only 3 backticks.