reReplace(str, "@([a-zA-Z0-9]{1,16})", "@<a href='test'>\1</a> ", "all")

change 16 to the max length of your usernames. I'm just assuming you have a
max length since you started to specify 1 through something but didn't
finish... you just have {1,}

..:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.
Bobby Hartsfield
http://acoderslife.com


-----Original Message-----
From: Andy Jarrett [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, November 07, 2007 2:04 PM
To: CF-Talk
Subject: Wierd regex problem (isn't it always)

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>



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Enterprise web applications, build robust, secure 
scalable apps today - Try it now ColdFusion Today
ColdFusion 8 beta - Build next generation apps

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:292885
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