Compiled Regular Expression...setup during runtime...

If one specifies that the regular expression should be compiled into the assembly, how does that affect a dynamic creation of the expression For example, the areas in red are specific to the string.format where a delimiter defined at runtime that is being inserted.

Regex(string.Format("( <={0}|^)( :\") ( <Column>[\\w\\.\\- ]*)( :\") ( ={0}|$)", this.Delimiter), RegexOptions.Singleline | RegexOptions.ExplicitCapture | RegexOptions.Compiled);

Since it is generated at runtime...how, or if, does that affect that it will be compiled into the assembly

Or am I misunderstanding compiled The documentation says the first time run it will incur a penalty...

Specifies that the regular expression is compiled to an assembly. This yields faster execution but increases startup time.

When is that startup time When it is encountered or when it is compiled by the developer or when the assembly is initially loaded.

advTHANKSance



Answer this question

Compiled Regular Expression...setup during runtime...

  • tblazing28

    The Regex constructor "initializes and compiles a new instance of the Regex class for the specified regular expression, with options that modify the pattern" (MSDN). Most probably this means that the Regex is compiled everytime you call the constructor with different parameters.
  • spotty

    Thanks for the information. The connotation of compiled can mean different things...thanks for the clarification.


  • VitCon

    The compiled option is generally used when you have an expression that you will be using over and over in your application. If you are dynamically creating an expression and matching it to an input and then throwing it away I would recommend against using the Compiled option. The Compiled option causes the Regex class to actually generate the code for the expression at runtime. This cause a significant perf degrade the first time you use the expression over not using this option. However subsequent matches should be faster and will eventually make up for the initial cost of creating the code.

    Ryan Byington [MS]



  • Compiled Regular Expression...setup during runtime...