I'm looking to replace/remove all line breaks within a given string except for ones nested within a <pre>
tag. So for the following string:
var text = @"
Some contents which is formatted
over multiple
lines but contains a
<pre>
tag which has
also has
multiple line breaks.
</pre>
";
I would like to remove all line breaks except for ones nested within a pre tag:
Regex.Replace(text, "\n", "<br />");
Use a negative look ahead and you can still do it in one line:
Here's some test code, with a better sample containing multiple
<pre>
tags:Output:
Is not beautiful, but works for me.