Usually, when I'm replacing newlines I jump to Regexp, like in this PHP
preg_replace('/\R/u', " ", $String);
Because I know that to be a very durable way to replace any kind of Unicode newline (be it , , , etc.)
I was trying to something like this in Go as well, but I get
error parsing regexp: invalid escape sequence:
On this line
msg = regexp.MustCompilePOSIX("\\R").ReplaceAllString(html.EscapeString(msg), "<br> ")
I tried using
)|\v) from https://stackoverflow.com/a/4389171/728236, but it looks like Go's regex implementation doesn't support that either, panicking with
invalid or unsupported Perl syntax: '(?>'
What's a good, safe way to replace newlines in Go, Regex or not?
I see this answer here Golang: Issues replacing newlines in a string from a text file saying to use
, but I'm hesitant to believe that it would get all Unicode newlines, mainly because of this question that has answer listing many more newline codepoints than the 3 that