remove spaces in string with regular expression javascript code example Example: remove whitespace with regex javascript return str.replace(/\s/g, '');