<cffunction
name="REMatchGroup"
access="public"
returntype="array"
output="false"
hint="Gets the given group of a captured expression.">
<cfargument
name="Pattern"
type="string"
required="true"
hint="The regular expression we want to match on."
/>
<cfargument
name="Text"
type="string"
required="true"
hint="The target text against which we will run the patterns."
/>
<cfargument
name="Group"
type="numeric"
required="false"
default="0"
hint="The captured group we want to return."
/>
<cfset var LOCAL = {} />
<cfset LOCAL.Results = [] />
<cfset LOCAL.Pattern = CreateObject(
"java",
"java.util.regex.Pattern"
).Compile(
JavaCast( "string", ARGUMENTS.Pattern )
)
/>
<cfset LOCAL.Matcher = LOCAL.Pattern.Matcher(
JavaCast( "string", ARGUMENTS.Text )
) />
<cfloop condition="LOCAL.Matcher.Find()">
<cfset ArrayAppend(
LOCAL.Results,
LOCAL.Matcher.Group(
JavaCast( "int", ARGUMENTS.Group )
)
) />
</cfloop>
<cfreturn LOCAL.Results />
</cffunction>