It is not possible to construct a "plain" regex to recognize strings with balanced parentheses from strings with unbalanced parentheses, because the underlying programmable system of regex is not powerful enough to do it. For the same reason, it is theoretically impossible to construct a regular expression that could recognize a well-formed XML*.
Even if it were possible theoretically to construct such expression, it would not be practical: the amount of work needed to build a recognizer would be roughly the same as the amount of work needed to build a full-fledged XML parser.
Luckily, .NET comes with several XML parsers already. A piece of code like this
bool TryGetValidXml(string s, out XDoxument res) {
try {
res = XDocument.Load(s);
return true;
} catch {
res = null;
return false;
}
}
would do the trick.
* There are various extensions, such as Perl's
recursive regex and .NET
balancing groups that let you work around this limitation.