local str = "string with\nnew line" str = string.gsub(str, "[^%S\n]+", "") print(str)