Read this about RegexOptions.Compiled
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconcompilationreuse.asp
The MSIL generated can not be unloaded, that can be extremely problematic.
Posted by Carlos Perez at February 17, 2003 5:39 PMYes, I know that RegExs that use RegexOptions.Compiled cannot be unloaded, and therefore this option cannot be applied all the time.
Many (if not most) times you use a RegEx, the expression is a constant though so the RegEx can be created as a static field with RegExOptions.Compiled turned on. Also, if there are only a limited number of variations of dynamically created RegExs, you could potentially store them in a Hashtable to avoid recreating the same one more than once.
Since Java does not have a Compiled option, I had expected the .NET RegEx to be at least as fast as the Java implementation. The fact that it was still over twice as slow really shows the maturity of the Java libraries and the HotSpot VM.
Posted by Luke Hutteman at February 25, 2003 12:39 AM