Adobe COLDFUSION 9 Manual page 147

Developing applications
Hide thumbs Also See for COLDFUSION 9:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
The CFML Programming Language
Element one of the
array contains the starting index in the search string of the string that matched the regular
pos
expression. Element one of the
" BIG " string is 5 and its length is also 5. If the regular expression does not occur, the
one element with a value of 0.
You can use the returned information with other string functions, such as
part of the search string matching the regular expression:
<cfset myString="Some BIG BIG string">
<cfset sLenPos=REFind(" BIG ", myString, 1, "True")>
<cfoutput>
#mid(myString, sLenPos.pos[1], sLenPos.len[1])#
</cfoutput>
Each additional element in the
string. Each additional element in
In the previous example, the regular expression " BIG " contained no subexpressions. Therefore, each array in the
structure returned by
REFind
After executing the previous example, you can call
expression. This time, you use the information returned by the first call to make the second:
<cfset newstart = sLenPos.pos[1] + sLenPos.len[1] - 1>
<!--- subtract 1 because you need to start at the first space --->
<cfset sLenPos2=REFind(" BIG ", "Some BIG BIG string", newstart, "True")>
<cfoutput>
<cfdump var="#sLenPos2#">
</cfoutput><br>
If you include subexpressions in your regular expression, each element of
position and length of the first occurrence of each subexpression in the search string.
In the following example, the expression [A-Za-z]+ is a subexpression of a regular expression. The first match for the
expression ([A-Za-z]+)[ ]+, is "is is".
<cfset sLenPos=REFind("([A-Za-z]+)[ ]+\1",
"There is is a cat in in the kitchen", 1, "True")>
<cfoutput>
<cfdump var="#sLenPos#">
</cfoutput><br>
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
returns information on the first regular expression match only, the
REFind
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>
array contains length of the matched string. For this example, the index of the first
len
array contains the position of the first match of each subexpression in the search
pos
contains the length of the subexpression's match.
len
contains a single element.
REFind
Last updated 8/5/2010
pos
. The following example returns that
mid
a second time to find the second occurrence of the regular
and
after element one contains the
pos
len
sLenPos
and
arrays each contain
len
structure does not
142

Advertisement

Table of Contents
loading

Table of Contents