The compile function
is used with a regular expression object. You must define a regular
expression object first as a variable before you can use COMPILE(
) to compile a PERL-compatible regular expression. Regular expressions
can be used to do advanced pattern matching (and in some cases pattern
replacement). Use the other functions listed below to find patterns
in a given string (which can be a variable), to determine the length
of matching patterns, and to replace patterns.
The function returns
1 if the regular expression compilation is successful. Otherwise,
it returns 0. Failure could be due to an incorrectly formatted regular
expression or possibly an invalid encoding constant.
For performance reasons,
it is best to compile a regular expression in a preprocessing step
in the Expression node. This means that the
regular expression is compiled just once before data rows are processed
by the Expression node.
Note: The sample code in this section
generally places the COMPILE() function on the Expression tab
with the rest of the expression code for clarity.
In some cases, you might
need to compile the regular expression before every row is evaluated.
For example, you can use a variable to define the regular expression
that you want to compile. The variable might come from the data row
itself, and you would need to recompile the regular expression for
each row to have the pattern searching work correctly.
Take care to design
regular expressions that find patterns only for which you want to
search. Poorly written regular expression code can require a lot of
additional processing that can negatively impact performance.