I assume that you are using code using Windows. Please note that if you print the length of the resulting string, it will display more than 100 characters. The reason is that Windows not only uses newlines ( \n ), but it also returns carriage returns ( \r ), so on Windows itβs actually \r\n , not \n . To filter them correctly from your string, use:
re = regexp.MustCompile(`\r?\n`) input = re.ReplaceAllString(input, " ")
Back tags will ensure that you don't need to specify a backslash in a regular expression. I used a question mark to return a carriage to make sure your code works on other platforms as well.
source share