Hi

I'm trying to do a look through as string to find usernames and add
<a> tags around them ala Twitter.

The regex I think is fine but when I use reReplace 's back reference
I'm not getting the result I thought I would of. Heres the code. Can
anyone see anything obvious?

Cheers, Andy


<!--- String to be manipulated --->
<cfset str = "First username is @andrew and second is @jarrett" />
<cfoutput><p>#str#</p></cfoutput>       


<!--- The Regex
        (@){1} - First back reference is the @ sign. Look for one of these
        ([a-zA-Z0-9]){1,} - Second back reference is the username
--->
<cfset reg = "(@){1}([a-zA-Z0-9]){1,}" />

<!--- Using reReplace we take the second back reference and wrap
an <a> tag around it --->
<cfset usernamePos = reReplace(str, reg, "@<a href='test'>\2</a>", "all") >
        
<cfoutput>#usernamePos#</cfoutput>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
ColdFusion 8 - Build next generation apps
today, with easy PDF and Ajax features - download now
http://download.macromedia.com/pub/labs/coldfusion/cf8_beta_whatsnew_052907.pdf

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:292863
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to