Regular Expression to match cross platform newline characters
The regex I use when I want to be precise is "\r\n?|\n"
.
When I'm not concerned about consistency or empty lines, I use "[\r\n]+"
, I imagine it makes my programs somewhere in the order of 0.2% faster.
The pattern can be simplified to \r?\n
for a little performance gain, as you probably don't have to deal with the old Mac style (OS 9 is unsupported since February 2002).