Regex that matches a newline (\n) in C#

If you specify RegexOptions.Multiline then you can use ^ and $ to match the start and end of a line, respectively.

If you don’t wish to use this option, remember that a new line may be any one of the following: \n, \r, \r\n, so instead of looking only for \n, you should perhaps use something like: [\n\r]+, or more exactly: (\n|\r|\r\n).

Leave a Comment