My requirement is to match each line of a text file, including the line terminator of each, at most excluding the terminator of the last line, to take into account the crippled, non POSIX-compiant files generated on Windows; each line terminator can be either \n
or \r\n
.
As a consequence, no character in the file should be left unmatched.
The best regex I could come up with is this:
\n|\r\n|[^\r\n]++(\r\n|\n)?
Is this the best I can write, performance-wise?
Please, if you use the ^
/$
anchors or similar, comment about that, because their behavior is dependent on whether the engine considers them as multiline by default.