A handful of comments:

Backreferencing a single, static character is silly.  It just wastes 
memory and processor time.  You're throwing it away, anyway.

{1} is useless.  It means "one of".  Which would just be the thing by 
itself.

Second, {1,} is more commonly written +.  Also, you are saying "one or 
more backreferenced things" instead of "one or more backreferenced things.

I'd write it like this:
@([a-zA-Z0-9]+)
Then use the first backreference instead of the second.

--Ben Doom

Andy Jarrett wrote:
> 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>
> 
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Create robust enterprise, web RIAs.
Upgrade to ColdFusion 8 and integrate with Adobe Flex
http://www.adobe.com/products/coldfusion/flex2/?sdid=RVJP

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

Reply via email to