Learning ColdFusion 8: REMatch() For Regular Expression Matching

<!---
	Create a Java pattern that will match our H2 and A
	search results pattern.
--->
<cfset objPattern = CreateObject(
	"java",
	"java.util.regex.Pattern"
	).Compile(
		"(?i)<h2 class=r><a[^>]+>.+?</a></h2>"
		) />
 
 
<!---
	Create a matcher that will apply this pattern to
	our Google search results (that we scrapped via the
	CFHttp call above). This matcher will have the
	ability to loop over all pattern matches in the
	target string.
--->
<cfset objMatcher = objPattern.Matcher(
	objGet.FileContent
	) />
 
 
<!--- Create an array to hold our search results. --->
<cfset arrTitles = [] />
 
 
<!---
	Keep iterating over the matcher while there are
	still search results to be found.
--->
<cfloop condition="objMatcher.Find()">
 
	<!--- Add this match to our title array. --->
	<cfset ArrayAppend(
		arrTitles,
		objMatcher.Group()
		) />
 
</cfloop>
 
 
<!---
	At this point, our arrTitles should be an array that
	holds zero or more (hopefully more) matches to our
	above regular expression.
--->
<cfdump
	var="#arrTitles#"
	label="Maria Bello Is Hot Java Pattern / Matcher"
	/>

For Cut-and-Paste