regex to remove whitespace only from the sides javascript code example Example: remove whitespace with regex javascript return str.replace(/\s/g, '');