Macromedia coldfusion 4.5-cfml language reference User Manual

Page of 608
492
CFML Language Reference 
length of the first instance of each subexpression within the regular expression are 
returned in subsequent elements of the arrays.
Examples
<!--- This example shows the use of REFind --->
<HTML>
<HEAD>
<TITLE>
REFind Example
</TITLE>
</HEAD>
<BODY>
<H3>REFind Example</H3>
<P>This example demonstrates the use of the REFind function with and 
without the <i>returnsubexpressions</i> parameter set to True.</P> 
If you do not use the <i>returnsubexpressions</i> parameter, REFind 
returns the position of the first occurrence of a regular expression in a 
string starting from the specified position.  Returns 0 if no occurrences 
are found.
</P>
<P>REFind("a+c+", "abcaaccdd"):
<CFOUTPUT>#REFind("a+c+", "abcaaccdd")#</CFOUTPUT></P>
<P>REFind("a+c*", "abcaaccdd"):
<CFOUTPUT>#REFind("a+c*", "abcaaccdd")#</CFOUTPUT></P>
<P>REFind("[[:upper:]]", "abcaacCDD"):
<CFOUTPUT>#REFind("[[:upper:]]", "abcaacCDD")#</CFOUTPUT></P>
<P>REFind("[\?&]rep=", "report.cfm?rep=1234&u=5"):
<CFOUTPUT>#REFind("[\?&]rep=", "report.cfm?rep=1234&u=5")#</CFOUTPUT>
</P>
<!--- Set startPos to one; returnMatchedSubexpressions = TRUE --->
<hr size="2" color="#0000A0">
<P>If you do use the <i>returnssubexpression</i> parameter, REFind 
returns the position and length of the first occurrence of a regular 
expression in a string starting from the specified position. The position 
and length variables are stored in a structure. In order to access
the position and length information, you must use the keys <i>pos</i> and 
<i>len</i>, respectively.</P>
<CFSET teststring ="The cat in the hat hat came back!">
<P>The string in which the function is to search is: 
<CFOUTPUT><b>#teststring#</b></CFOUTPUT>.</P>
<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>