When not to use Regex in C# (or Java, C++, etc.)

Don’t try to use regex to parse hierarchical text like program source (or nested XML): they are proven to be not powerful enough for that, for example, they can’t, for a string of parens, figure out whether they’re balanced or not.

Use parser generators (or similar technologies) for that.

Also, I’d not recommend using regex to validate data with strict formal standards, like e-mail addresses.
They’re harder than you want, and you’ll either have unaccurate or a very long regex.

Leave a Comment