Extract HTML page title - ColdFusion regular expression

To extract a page title from a HTML page that has either been pulled from CFHTTP, a stored local file or from the ColdFusion page output:-

<cfset pageTitle = "">
<cfset RegExp = REFindNoCase("(<title[>])(.*)(<\/title>)", myFile, 1, True)>
<cfif RegExp.len[1] gt 0>
  <cfset pageTitle = mid(myFile, RegExp.pos[3], RegExp.len[3])>
</cfif>
TweetBacks
Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
I tried using your example to extract the contents of the first paragraph from a HTML page by substituting "p" for "title" but it extracted everything from the first opening <p> to the last </p> on the page. Could you advise how to alter the regular expression to select just the first paragraph? Thank you!
# Posted By Eric | 02/05/07 14:37
Put a question mark in the end ?
it'll make it non-greedy, and try to select as little text as possible that matches the criteria.
# Posted By Zeev Russak | 13/04/08 13:23
Thanks for the starter code. This will grab the content in the first title tag when multiple tags are present. I'm using cfhttp.fileContent to as the haystack.

<cfset pageTitle = "">
      <cfset RegExp = REFindNoCase("<title\b[^>]*?>([^<]+)</title>", cfhttp.fileContent, 1, True)>
<cfif RegExp.len[2] gt 0><!--- Get 2nd grouping --->
<cfset pageTitle = mid(cfhttp.fileContent, RegExp.pos[2], RegExp.len[2])>
</cfif>
# Posted By R. Eden | 03/06/08 16:17
BlogCFC was created by Raymond Camden. This blog is running version 5.9.5.002. Contact Blog Owner