
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
576
|
Chapter 10: Regular Expressions
This code displays the following text:
mName.Value = NAME
Note that this code can be used as part of your build process. The resulting assem-
bly can then be shipped with your application.
Discussion
Compiling regular expressions allows the expression to run faster. To understand
how, you need to examine the process that an expression goes through as it is run
against a string. If an expression is not compiled, the regular expression engine con-
verts the expression to a series of internal codes that are recognized by the regular
expression engine; it is not converted to MSIL. As the expression runs against a
string, the engine interprets the series of internal codes. This can be a slow process,
especially as the source string becomes very large and the expression becomes much
more complex.
There is a class of scenarios for which performance of uncompiled regex is unaccept-
able, but for which compiled regex performs acceptably. To mitigate this perfor-
mance problem, you can compile the expression so that it gets converted directly to a
series of MSIL instructions, which performs the pattern matching for the specific reg-
ular expression. Once the Just-In-Time (JIT) compiler is run on this MSIL, the
instructions are converted to machine code. This