MACROMEDIA COLFUSION MX 7-CFML Reference page 809

Cfml reference
Hide thumbs Also See for COLFUSION MX 7-CFML:
Table of Contents

Advertisement

<p>The first call to REFind to search this string is:
<b>REFind("[A-Za-z]+",testString,1,"TRUE")</b></p>
<p>This function returns a structure that contains two arrays: pos and len.</p>
<p>To create this structure you can use a CFSET statement, for example: </p>
&lt;CFSET st = REFind("[[:alpha:]]",testString,1,"TRUE")&gt;
<cfset st = REFind("[[:alpha:]]",testString,1,"TRUE")>
<p>
<cfoutput>
The number of elements in each array: #ArrayLen(st.pos)#.
</cfoutput></p>
<p><b>The number of elements in the pos and len arrays is always one
if you do not use parentheses in the regular expression.</b></p>
<p>The value of st.pos[1] is: <cfoutput>#st.pos[1]#.</cfoutput></p>
<p>The value of st.len[1] is: <cfoutput>#st.len[1]#.</cfoutput></p>
<p>
<cfoutput>
Substring is <b>[#Mid(testString,st.pos[1],st.len[1])#]</B>
</cfoutput></p>
<hr size = "2" color = "#0000A0">
<p>However, if you use parentheses in the regular expression, the first
element contains the position and length of the first instance
of the whole expression. The position and length of the first instance
of each parenthesized subexpression within is included in additional
array elements.</p>
<p>For example:
&lt;CFSET st1 = REFind("([[:alpha:]])[ ]+(\1)",testString,1,"TRUE")&gt;</p>
<cfset st1 = REFind("([[:alpha:]]+)[ ]+(\1)",testString,1,"TRUE")>
<p>The number of elements in each array is <cfoutput>#ArrayLen(st1.pos)#
</cfoutput>.</p>
<p>First whole expression match; position is
<cfoutput>#st1.pos[1]#;
length is #st1.len[1]#; whole expression match is
<B>[#Mid(testString,st1.pos[1],st1.len[1])#]</B>
</cfoutput></p>
<p>Subsequent elements of the arrays provide the position and length of
the first instance of each parenthesized subexpression therein.</p>
<cfloop index = "i" from = "2" to = "#ArrayLen(st1.pos)#">
<p><cfoutput>Position is #st1.pos[i]#; Length is #st1.len[i]#;
Substring is <B>[#Mid(testString,st1.pos[i],st1.len[i])#]
</B></cfoutput></p>
</cfloop><br>
REFind
809

Advertisement

Table of Contents
loading

This manual is also suitable for:

Colfusion mx 7 - installing and using coldfusion mx

Table of Contents