regex remove all spaces left and right string code example Example: regex to remove spaces //.. return str.replace(/\s/g, ''); //..