You can find all whitespace that does not exist after an opening PRE (that isn't followed by a closing PRE) and that does not exist before a closing PRE (that isn't preceeded by an opening PRE). That would require a negative lookahead and a negative lookbehind that themselves contain a negative lookahead and a negative lookbehind. I've never tried combining negative lookaheads/lookbehinds like that, so I'm not sure it would work, but it seems like that would be the way to go. I'll let you figure out the regex, but pseudo-regex would be something like this:
(must not contain a PRE that is not followed by a /PRE)
(?<=(.|\n)*)
whitespace
(?=(.|\n)*)
(must not contain a /PRE that is not preceeded by a PRE)
Here is what a negative lookbehind looks like:
(?<!\<PRE\>)
Here is what a negative lookahead looks like:
(?!\<\/PRE\>)
You'll have to do some testing to play with the nesting, as I am not quite sure how that works.
Check out
this reference for more C# regex help.