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)
.
Actually it works but with opposite option i.e.
RegexOptions.Singleline
You are probably going to have a \r before your \n. Try replacing the \s with (\r\n).