Game Development Reference
In-Depth Information
In order to further increase performance when executing a regular expression,
there is support for pre-compiling a regular expression to MSIL, which will then
be JIT'ed (Just-in-Time compiled) to native code before execution. Pre-compiled
regular expressions are placed in dynamically generated assemblies that can be
loaded at runtime within an application domain. Assemblies cannot be unloaded,
so there is a potential problem with this approach where you will not be able to
unload regular expressions from memory until the application domain itself is
released. To solve this problem, you can persist the dynamically generated assem-
blies to the hard drive and load them at runtime into a second application domain.
This functionality is available through the Regex.CompileToAssembly() method.
The following code shows how to compile a regular expression to a dynamically
generated assembly.
using System;
using System.Reflection;
using System.Text.RegularExpressions;
string name = “AlphaNumericTest”;
string nameSpace = “CompiledExpression”;
string assembly = “RegularExpressionTest”;
string expression = “[^a-zA-Z0-9]”;
RegexOptions options = RegexOptions.None;
RegexCompilationInfo info = new RegexCompilationInfo(expression,
AssemblyName assemblyName = new AssemblyName();
assemblyName.Name = assembly;
Regex.CompileToAssembly(new RegexCompilationInfo[]{info}, assemblyName);
The following code shows how to use the regular expression that has been com-
piled into the RegularExpressionTest assembly.
using System;
using System.Text.RegularExpressions;
string searchString = “Your Search String Here”;
CompiledExpression.AlphaNumericTest expression
= new CompiledExpression.AlphaNumericTest();
foreach (Match match in expression.Matches(searchString))
Search Nedrilad ::

Custom Search