get rid of spaces js regex code example Example: remove whitespace with regex javascript return str.replace(/\s/g, '');