Learning ColdFusion 8: REMatch() For Regular Expression Matching

<!---
	Let's search for some google results for the phrase
	"Maria Bello is hot" (seriously!!). We are going to
	grab the first page in our CFHttp object.
--->
<cfhttp
	url="http://www.google.com/search?q=maria+bello+is+hot"
	method="GET"
	useragent="#CGI.http_user_agent#"
	result="objGet">
 
	<!---
		Tell Google that we just came from the Google.com
		home page. This is not necessary, really, but it is
		good practice when dealing with better security.
	--->
	<cfhttpparam
		type="CGI"
		name="referer"
		value="http://www.google.com"
		/>
 
</cfhttp>
 
 
<!---
	Now, we want to grab all of the titles from our
	search results. Based on looking at the source of
	the results page, we can gather that there is a
	consistent pattern for the HTML. We can use this
	pattern to create a regular expression based on
	the H2 tags and A tags.
--->
<cfset arrTitles = REMatch(
	"(?i)<h2 class=r><a[^>]+>.+?</a></h2>",
	objGet.FileContent
	) />
 
 
<!---
	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 REMatch()"
	/>

For Cut-and-Paste