What does this expression return?
' hi '.replace(/^\s+|\s+$/g, '')
- 'hi'
- 'hi '
- ' hi'
- ' hi '
The two alternatives strip leading and trailing whitespace;
Play Regex ▸
g lets both run.' hi '.replace(/^\s+|\s+$/g, '')
g lets both run.