Regex.Replace(str, @"\s", ""); code example Example: regex replace / // replaces all / in a String with _ str = str.replace(/\//g,'_');