User Guide

Table Of Contents
156 Chapter 7: Using Regular Expressions in Functions
For example, you use the regular expression "<b>(.*)</b>" to search the string "<b>one</b>
<b>two</b>". The regular expression "<b>(.*)</b>", matches both of the following:
<b>one</b>
<b>one</b> <b>two</b>
By default, ColdFusion always tries to match the regular expression to the largest string in the
search string. The following code shows the results of this example:
<cfset sLenPos=REFind("<b>(.*)</b>", "<b>one</b> <b>two</b>", 1, "True")>
<cfoutput>
<cfdump var="#sLenPos#">
</cfoutput><br>
The following figure shows the output of the cfdump tag:
Thus, the starting position of the string is 1 and its length is 21, which corresponds to the largest
of the two possible matches.
However, sometimes you might want to override this default behavior to find the shortest string
that matches the regular expression. ColdFusion includes minimal-matching quantifiers that let
you specify to match on the smallest string. The following table describes these expressions:
If you modify the previous example to use the minimal-matching syntax, the code is as follows:
<cfset sLenPos=REFind("<b>(.*?)</b>", "<b>one</b> <b>two</b>", 1, "True")>
<cfoutput>
<cfdump var="#sLenPos#">
</cfoutput><br>
Expression Description
*? minimal-matching version of *
+? minimal-matching version of +
?? minimal-matching version of ?
{min,}? minimal-matching version of {min,}
{min,max}? minimal-matching version of {min,max}
{n}? (no different from {n}, supported for notational consistency)