reFindAll(regExpression, string[, start][, caseSensitive])
Last updated October 12, 2011
Version: 1 | Requires: CF6 | Library: StrLib
Description:
Like Ben Forta's reFindAll (which this replaces), except case sensitivity can be toggled and a start position can be defined. Also it returns an array of structs instead of one big struct
Return Values:
Returns an array of structs.
Example:
<cfdump var="#refindall('CAT_([\d]+)','SUBMIT2CAT_1CAT_2CAT_3cat_4',1,false)#">
Parameters:
Name | Description | Required |
---|---|---|
regExpression | The regular expression to test with | Yes |
string | String to search. | Yes |
start | Starting position. Defaults to 1. | No |
caseSensitive | Whether or not to use case sensitive matching. Defaults to false. | No |
Full UDF Source:
<!---
Finds all occurences of a regex in a string.
@param regExpression The regular expression to test with (Required)
@param string String to search. (Required)
@param start Starting position. Defaults to 1. (Optional)
@param caseSensitive Whether or not to use case sensitive matching. Defaults to false. (Optional)
@return Returns an array of structs.
@author Raymond Selzer (raymond@kingcommedia.com)
@version 1, October 11, 2011
--->
<cffunction name="reFindAll" output="yes" returntype="array">
<cfargument name="regExpression" type="string" required="yes">
<cfargument name="string" type="string" required="yes">
<cfargument name="start" type="numeric" required="no" default="1">
<cfargument name="caseSensitive" type="boolean" required="no" default="false">
<cfset var result = arrayNew(1)>
<cfset var matches = ''>
<cfif caseSensitive>
<cfset matches = refind(regExpression,string,start,true)>
<cfelse>
<cfset matches = refindnocase(regExpression,string,start,true)>
</cfif>
<cfloop condition="#matches.len[1]# neq 0">
<cfset result[arraylen(result) + 1] = matches>
<cfset start = matches.pos[1] + matches.len[1]>
<cfif caseSensitive>
<cfset matches = refind(regExpression,string,start,true)>
<cfelse>
<cfset matches = refindnocase(regExpression,string,start,true)>
</cfif>
</cfloop>
<cfreturn result>
</cffunction>
Search CFLib.org
Latest Additions
Raymond Camden added
QueryDeleteRows
November 04, 2017
Leigh added
nullPad
May 11, 2016
Raymond Camden added
stripHTML
May 10, 2016
Kevin Cotton added
date2ExcelDate
May 05, 2016
Raymond Camden added
CapFirst
April 25, 2016