No problem. I spotted some odd bugs (that you probably wont run into often if at all) but this should take care of those as well.
<cfsavecontent variable="thetext"> <a href="http://mysite.com" target="_blank">1</a><br> <a href="http://mysite.com" target="_self" title="something">2</a><br> <a href="http://mysite.com">3</a><br> <a target=_blank href="http://mysite.com">4</a><br> <a href="http://mysite.com" target='_nada'>5</a><br> here's an odd link test <a href="http//somewhere.com" target="_blank" title="something">target=bullseye</a><br> here's an odd link test <a href="http//somewhere.com" target='bullseye'>target=bullseye</a><br> here's an odd link test <a href="http//somewhere.com" target=bullseye>target=bullseye</a><br> </cfsavecontent> <cfscript> function targetlinks(str, targ) { str = rereplacenocase(str,'(<a +.*?)( target=).*?([ |>])',"\1\3", "ALL"); str = replacenocase(str, "<a ", "<a target=""#targ#"" ", "ALL"); return str; } </cfscript> <cfoutput>#targetlinks(thetext, "_blank")#</cfoutput> Also, the previous message had "thetext" in the second replace where it should have been "str". Sorry, I flew through it the first go round. Let me know if you run into any odd problems. I will most likely get some use out of this myself. ~Bobby -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Saturday, September 03, 2005 5:38 PM To: CF-Talk Subject: RE: Trying to ensure links have a target attribute Thanks! Dave -----Original Message----- From: Bobby Hartsfield [mailto:[EMAIL PROTECTED] Sent: Saturday, September 03, 2005 5:10 PM To: CF-Talk Subject: RE: Trying to ensure links have a target attribute Try this. It should take care of all instances you run across. If the raget attribute is in fact in a valid link, it either ends with a space or a closing bracket > <cfsavecontent variable="thetext"> <a href="http://mysite.com" target="_blank">1</a><br> <a href="http://mysite.com" target="_self" title="something">2</a><br> <a href="http://mysite.com">3</a><br> <a target=_blank href="http://mysite.com">4</a><br> <a href="http://mysite.com" target='_nada'>5</a><br> </cfsavecontent> <cfscript> function targetlinks(str, targ) { str = rereplacenocase(str,'( target=.*?)([ |>])',"\2","ALL"); str = replacenocase(thetext, "<a ", "<a target=""#targ#"" ", "ALL"); return str; } </cfscript> <cfoutput>#targetlinks(thetext, "_blank")#</cfoutput> The first rereplace strips out all target attributes. The second puts the attribute back with the value you pass to the function. It seems to work with everything I've thrown at it thus far. ~Bobby -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Saturday, September 03, 2005 3:57 PM To: CF-Talk Subject: RE: Trying to ensure links have a target attribute Okay, this is what I got, and it works, but I'm wondering if there's a way to combine all three replaces into one: <cfset text = REReplaceNoCase(text,'target="[^"]*"',"","ALL")> <cfset text = REReplaceNoCase(text,"target='[^']*'","","ALL")> <cfset text = REReplaceNoCase(text,'target=[^>|^ ]*',"","ALL")> <cfset text = ReplaceNoCase(text,"<a ",'<a target="_blank" ',"ALL")> What do you think? Also, if you see something wrong with these, please let me know. I've tested and it seems to work right, but I don't know if it might actually get something I'm not thinking of. Thanks, Dave **************************************************************************** ************** The information contained in this message, including attachments, may contain privileged or confidential information that is intended to be delivered only to the person identified above. If you are not the intended recipient, or the person responsible for delivering this message to the intended recipient, ALLTEL requests that you immediately notify the sender and asks that you do not read the message or its attachments, and that you delete them without copying or sending them to anyone else. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Discover CFTicket - The leading ColdFusion Help Desk and Trouble Ticket application http://www.houseoffusion.com/banners/view.cfm?bannerid=48 Message: http://www.houseoffusion.com/lists.cfm/link=i:4:217306 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4 Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

