Regular Expression – Compiled vs Interpreted

Regular Expression gives the developer a clean and efficient method to parse strings. However, it comes at a cost – there is a inherent performance hit associated with regular expressions, especially if you are running some kind of long loops and parsing the string inside it. One way to tackle it is using compiled regular expressions, which .Net provides by using the RegexOptions.Compiled property. Let’s examine the performance of the Interpreted version of regular expression and the compiled version in a long loop.

We will consider a simple regular expression that is intended to parse a valid date.