Sorcerer's IsleDocs cfRegexOverviewCode

cfregex Tag

The cfregex tag provides a convenient way to use long or complicated regex, by allowing the regex pattern to be freely spaced and interspersed with comments, which makes the expression far more understandable and maintainable.

The tag can be used either to compile a Regex Object, or for any of the actions which are available.

Creating an Object

To compile a regex object, simply use the tag with the name attribute to indicate the variable name to hold the created object:

<cfregex name="MyRx">
    ...pattern...
</cfregex>

You can optionally specify modes to apply:

<cfregex name="MyRx" modes="CASE_INSENSITIVE,DOTALL">
    ...pattern...
</cfregex>

Executing an Action

If you do not need a re-usable object, you can call actions directly, using the variable attribute to hold the result, with both of the following syntaxes being supported:

<cfregex action="match" variable="MatchResults" ...other parameters... >
    ...pattern...
</cfregex>

Or:

<cfregex match variable="MatchResults" ...other parameters... >
    ...pattern...
</cfregex>

The two different syntaxes are purely stylistic - they both work in exactly the same way.

Note also that whilst variable is used instead of name here, this is simply a matter of following existing CFML conventions; the two attributes are actually interchangable, and either one can be used in any situation.

All other parameters work in the same way as they do for functions or object-form (as described on the individual action's documentation page), and can either be supplied directly or by using attributecollection.