How can I replace lone instances of \\n with \\r\\n (LF alone with CRLF) using a regular expression in C#?
Sorry if it\'s a stupid question, I\'m new to Regex.
If I know the line endings must be one of CRLF or LF, something that works for me is
myStr.Replace("\r?\n", "\r\n");
This essentially does the same neslekkiM's answer except it performs only one replace operation on the string rather than two. This is also compatible with Regex engines that don't support negative lookbehinds or backreferences.