User Guide

Table Of Contents
Returning matched subexpressions 155
The following figure shows the output of the cfdump tag:
The entries sLenPos.pos[1] and sLenPos.len[1] contain information about the match of the entire
regular expression. The array elements sLenPos.pos[2] and sLenPos.len[2] contain information
about the first subexpression (“is”). Because
REFind returns information on the first regular
expression match only, the
sLenPos structure does not contain information about the second
match to the regular expression, "in in".
The regular expression in the following example uses two subexpressions. Therefore, each array in
the output structure contains the position and length of the first match of the entire regular
expression, the first match of the first subexpression, and the first match of the second
subexpression.
<cfset sString = "apples and pears, apples and pears, apples and pears">
<cfset regex = "(apples) and (pears)">
<cfset sLenPos = REFind(regex, sString, 1, "True")>
<cfoutput>
<cfdump var="#sLenPos#">
</cfoutput><br><br>
The following figure shows the output of the cfdump tag:
For a full discussion of subexpression usage, see the sections on
REFind and REFindNoCase in the
ColdFusion functions chapter in CFML Reference.
Specifying minimal matching
The regular expression quantifiers ?, *, +, {min,} and {min,max} specify a minimum and/or
maximum number of instances of a given expression to match. By default, ColdFusion locates the
greatest number characters in the search string that match the regular expression. This behavior is
called maximal matching.