Regular Expression Examples - Adobe 38043740 - ColdFusion Standard - Mac Development Manual

Developing applications
Hide thumbs Also See for 38043740 - ColdFusion Standard - Mac:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
The CFML Programming Language
For a full discussion of subexpression usage, see the sections on
functions chapter in the CFML Reference.
Specifying minimal matching
The regular expression quantifiers ?, *, +, {min,} and {min,max} specify one or both of a minimum and 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.
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>
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:
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)
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>
Thus, the length of the string found by the regular expression is 10, corresponding to the string "<b>one</b>".

Regular expression examples

The following examples show some regular expressions and describe what they match:
and
REFind
Last updated 1/20/2012
in the ColdFusion
REFindNoCase
143

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents