Name
REFind
Synopsis
REFind(regex, string
[,startpos
] [,returnsubexpressions
])
Performs a case-sensitive search. 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
arrays, pos
and len
that
represents the position and length, respectively, of the matched
regular expression. If the regular expression contains parenthesized
subexpressions, the first index of the array returns the
len
and pos
of the first
occurrence of the match for the entire regular expression. Each
subsequent array index in the returned structure contains the
len
and pos
for the first
occurrence of each parenthesized subexpression in 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 ratio of good to bad apples is 4:1."> <cfset matches= REFind("([0-9]+):([0-9]+)", MyString, 1, "true")> <cfoutput> <b>String:</b> #MyString#<br> <b>Regex:</b> REFind("([0-9]+):([0-9]+)", MyString, 1, "true")<br> <b>Position:</b> #matches.pos[1]#<br> <b>Length:</b> #matches.len[1]# </cfoutput> <p> Dump: <cfdump var="#matches#"> ...
Get Programming ColdFusion MX, 2nd Edition 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.