Extract HTML page title - ColdFusion regular expression
Related Categories: ColdFusion Regular Expressions
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 RegExp = REFindNoCase("(<title[>])(.*)(<\/title>)", myFile, 1, True)>
<cfif RegExp.len[1] gt 0>
<cfset pageTitle = mid(myFile, RegExp.pos[3], RegExp.len[3])>
</cfif>
ColdFusion - CFFORM (1) [RSS]
ColdFusion Regular Expressions (5) [RSS]
ColdFusion tips (3) [RSS]
database (1) [RSS]
Graphics software (1) [RSS]
JRun errors (1) [RSS]
Leisure time (3) [RSS]
Misc (2) [RSS]
Newly released BeetrootStreet websites (14) [RSS]
Search engine preparation (5) [RSS]
SQL Server hints and tips (1) [RSS]
Web application development (2) [RSS]
| Mon | Tue | Wed | Thu | Fri | Sat | Sun |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | ||
| 6 | 7 | 8 | 9 | 10 | 11 | 12 |
| 13 | 14 | 15 | 16 | 17 | 18 | 19 |
| 20 | 21 | 22 | 23 | 24 | 25 | 26 |
| 27 | 28 | 29 | 30 |
Cheap new cars in Australia
Martin Parry said: Haha - Well spotted ;-) I'll fix it now.
[More]
Cheap new cars in Australia
Sebastiaan said: There's been a lot of fuzz lately about no CF-work in Aussie and Kiwi country the last couple of yea...
[More]
Clearing ColdFusion memory using garbage collection when memory gets low
Jim S. said: Great post! Helped me a lot. I often look for video tutorials like this http://www.videorolls.com......
[More]
Adobe Dreamweaver CS3 crashes when selecting text in code view
Jonathan said: Thanks, totally solved my problem! Just deleted that DAT file and no more crashes!
[More]
CFFORM doesn't validate dropdown lists / combos even though required="true"
mrzam said: awesome charm! fix already!
[More]

it'll make it non-greedy, and try to select as little text as possible that matches the criteria.
<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>