I would like to compactly insert a <br />
tag before every line break in a string with regular expressions in C#. Can this be done? Currently, I am only able to replace the line break with the following:
myString = Regex.Replace(myString, @"\r\n?|\n", "<br />");
Can I modify this to include the matched text (i.e. either \r\n
, \r
, or \n
) in the replacement?
Clearly, it can be done with a separate Match variable, but I'm curious if it can be done in one line.