Macromedia coldfusion 4.5-cfml language reference User Manual
Chapter 2: ColdFusion Functions
493
<P>In order to create this structure you can use a CFSET statement, for
example: </P>
<CFSET st = REFind("[[:alpha:]]",testString,1,"TRUE")>
<CFSET st = REFind("[[:alpha:]]",testString,1,"TRUE")>
<P>
example: </P>
<CFSET st = REFind("[[:alpha:]]",testString,1,"TRUE")>
<CFSET st = REFind("[[:alpha:]]",testString,1,"TRUE")>
<P>
<CFOUTPUT>
The number of elements in each array: #ArrayLen(st.pos)#.
</CFOUTPUT>
</CFOUTPUT>
</P>
<P><b>The number of elements in the pos and len arrays will always be 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>
<P><b>The number of elements in the pos and len arrays will always be 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>
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, you will
find that 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 will be included in
additional array elements.</P>
find that 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 will be included in
additional array elements.</P>
<P>For example:
<CFSET st1 = REFind("([[:alpha:]])[
]+(\1)",testString,1,"TRUE")></P>
<CFSET st1 = REFind("([[:alpha:]])[
]+(\1)",testString,1,"TRUE")></P>
<CFSET st1 = REFind("([[:alpha:]]+)[ ]+(\1)",testString,1,"TRUE")>
<P>The number of elements in each array is
<CFOUTPUT>#ArrayLen(st1.pos)#</CFOUTPUT>.</P>
<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>
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)#">
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>
CFOUTPUT></P>
</CFLOOP><BR>
</BODY>
</HTML>
</HTML>