Andy, I'm not a regex ninja, like some, but I think what you're looking for is this. Escape the space character (using ^) so that any backreferences stop at the space character.
<cfset reg = "@([a-zA-Z0-9][^ ]+)" /> Then you can use the first backreference: <cfset usernamePos = reReplace(str, reg, "@<a href='test'>\1</a>", "all") > HTH, Jon On Nov 7, 2007, at 2:03 PM, 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:292893 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4