.NET Regular expressions have an extended ability to match "balanced items". For example, in the string
"a + (b+(c+d))" it can find correct pairs of matching open and closing brackets.
It's not the most simple solution in the world, so be ready for a small mind-melt when you read this from the BCL team (Base class library team at MS)