?

Log in

No account? Create an account
coldfusion_mx
..::.:.:. ..: .........: .:::..:::.
January 2010
          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
31

boxing_cat [userpic]
Regular Expressions

1.) This function removes HTML from the string

<cfscript>
function StripHTML(str) {
 return REReplaceNoCase(str,"<[^>]*>","","ALL");
}
</cfscript>

2.) This function finds URL in the string containing HTML

<cfscript>
function getURL(str) {
 
return REFindNoCase("(?:http|https|ftp|news)://(?:[@a-zA-Z0-9,/%:\&+##\?=\-_~;]+\.*)+[a-zA-Z0-9,/%:\&##\?=\-_]",str,1,"True");
}
</cfscript>

The use of a function and obtain a found link do the following:

<cfset b = getURL(training.title)>
<cfif b.pos[1] is not 0>
<cfset link = Mid(training.title, b.pos[1], b.len[1])>
</cfif>

After function is executed it returns two arrays pos[ ] and len[ ]. If there is no link found then the value of those arrays are 0 (zero). If it's found then Mid( ) function can be used to obtain the found link. Lenght of array indicates how many links have been found.