Until the developer of that filter provides this option, you can try the following: You can add a nested lookahead assertion to your regexes that precludes them from matching if a </pre>
tag follows (unless a <pre>
tag comes first). For the first three regexes, that means:
s = Regex.Replace(s, @"(?s)\s+(?!(?:(?!</?pre\b).)*</pre>)", " ");
s = Regex.Replace(s, @"(?s)\s*\n\s*(?!(?:(?!</?pre\b).)*</pre>)", "\n");
s = Regex.Replace(s, @"(?s)\s*\>\s*\<\s*(?!(?:(?!</?pre\b).)*</pre>)", "><");
Explanation of the lookahead assertion:
(?! # Assert that the following regex can't be matched here:
(?: # Match...
(?! # (unless the following can be matched:
</?pre\b # an opening or closing <pre> tag)
) # (End of inner lookahead assertion)
. # ...any character (the (?s) makes sure that this includes newlines)
)* # Repeat any number of times
</pre> # Match a closing <pre> tag
) # (End of outer lookahead assertion)
For the fourth regex, we must first make sure that .*?
doesn't match any <pre>
tags either
s = Regex.Replace(s, @"(?s)<!--((?:(?!</?pre\b).)*?)-->(?!(?:(?!</?pre\b).)*</pre>)", "");
Other than that, the regex works just as above.