Name

REFind

Synopsis

REFind(regex, string [, startpos] [, returnsubexpressions])

Returns the position of the first occurrence of regex in string. regex can be any valid ColdFusion regular expression. An optional starting position for the search can be specified by startpos. If returnsubexpressions is set to True (False is the default), REFind( ) returns a CFML structure containing two keys, pos and len, that represents the position and length, respectively, of the matched regular expression. If REFind( ) is unable to find a match for the regular expression, 0 is returned. REFind( ) performs a case-sensitive search. The following example demonstrates the use of the REFind( ) function with the returnsubexpressions parameter set to True:

<CFSET MyString="The name of the bank robber is Rob.">
<CFSET matches= ReFind("Rob", MyString, 1, "TRUE")>

<CFOUTPUT>
<B>String:</B>  #MyString#<BR>
<B>Regex:</B>  Refind(&quot;cat&quot;, MyString, 1, &quot;TRUE&quot;)<BR>
<B>Position:</B> #matches.pos[1]#<BR>
<B>Length:</B> #matches.len[1]#
</CFOUTPUT>

Get Programming ColdFusion now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.