Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a cross platform regex for removal of line breaks?

I am sure this has been asked before, but I cannot find it.

Basically, assuming you are parsing a text file of unknown origin and want to replace line breaks with some other delimiter, is this the best regex, or is there another?

(\r\n)|(\n)|(\r)

like image 341
Fletcher Moore Avatar asked Jul 10 '10 11:07

Fletcher Moore


1 Answers

Fletcher - this did get asked once before.

Here you go: Regular Expression to match cross platform newline characters

  • Spoiler Alert!

The regex I use when I want to be precise is "\r\n?|\n".

like image 104
Bobby B Avatar answered Sep 19 '22 08:09

Bobby B