regex remove spaces at end of line code example Example: regex to remove spaces //.. return str.replace(/\s/g, ''); //..