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