Returning Matched Subexpressions - MACROMEDIA COLDFUSION 5-DEVELOPING Develop Manual

Table of Contents

Advertisement

266

Returning Matched Subexpressions

The
matched subexpressions. If you set these functions' fourth parameter,
ReturnSubExpression
arrays containing the positions and lengths of text strings that match the
subexpressions of the first instance of a matched regular expression pattern.
The returned structure has two keys,
position of the subexpressions. The
The first element of each array contains information about the complete matched
expression, and indices 2 onwards contain information about the parenthesized
elements. If there are no occurrences of the regular expression, the
arrays each contain 1 element with a value of 0.
In the following example the first match for the expression ([A-Aa-z]+)[ ]+, is "is is".
The expression [A-Za-z]+ is a subexpression of the complete regular expression.
<cfset subExprs=REFind("([A-Za-z]+)[ ]+\1",
When ColdFusion executes the
subExprs.len[1]=5, subExprs.pos[2]=7, and subExprs.len[2]=2.
The entries subExprs.pos[1] and subExprs.len[1] refer to the entire matched
expression ("is is"), while subExprs.pos[2] and subExprs.len[2] refer to the first
parenthesized subexpression ("is"). Because
regular expression match only, the subExprs structure does not contain information
about the second match to the regular expression, "in in".
For a full discussion of subexpression usage, see the sections on REFind and
REFindNoCase in the ColdFusion Functions chapter of the CFML Reference.
and
REFind
REFindNoCase
, to True, the function returns a CFML structure with two
"There is is a cat in in the kitchen",1,"True")>
Chapter 14 Using Regular Expressions in Functions
functions allow you to get information about
and
. The
pos
len
array has the length of each subexpression.
len
function, subExprs.pos[1]=7,
ReFind
REFind
array contains the
pos
and
pos
returns information on the first
len

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 5

Table of Contents