Jon, My recommendation AGAINST using REFind() in a loop is that I feel like it has to keep revaluating the string. The Java Pattern matcher which is what powers the REMatchGroups() UDF is designed to iterate over pattern matches and as such I assume that it is really good at it. Plus, I think that you will find that dealing with the Len[] and Pos[] arrays is going to look less than elegant. I don't think there is anyone who has even enjoyed dealing with them :)
This is all theory though, I have never checked the performance. ...................... Ben Nadel Certified Advanced ColdFusion MX7 Developer www.bennadel.com Need ColdFusion Help? www.bennadel.com/ask-ben/ -----Original Message----- From: Jon Clausen [mailto:[EMAIL PROTECTED] Sent: Thursday, November 15, 2007 8:17 PM To: CF-Talk Subject: Re: Using reReplace Backreference as StructKey or Argument Ben, Thanks for the reply. I had sent a response to Ben's reply earlier today, but I guess it didn't go through. I figured the order of execution was the issue. I was hoping for a way to "trick" the execution order and tried writing the function call in a bunch of different ways other than the example I provided, but no dice. Ben posted a nice response, though looping with reFind() does the job for now. Thanks again, Jon On Nov 15, 2007, at 10:02 AM, Ben Doom wrote: > Sorry, you can't do that. Here's why: > > Coldfusion hands strings off to the regex engine. CF allows you to > used functions, variables, etc. in the string, but it executes them > *before* > the regex runs. So, in your first code sample, it's trying to find > the literal key \1 in appSettings, and then passing the result as the > replace value. > > --Ben Doom > > Jon Clausen wrote: >> I'm sure it's something simple that I'm missing, but I want to use a >> regex backreference as the struct key (i.e. - struct["key"]) or as >> an argument (i.e. - function("argument") ) but I've failed in all my >> attempts so far. >> >> For now I've written the code out using a loop with reFind(), >> returning subexpressions, mid(), etc. but it seems to me there should >> be a way to do this using reReplace() and pass the backreference as >> an argument/key. Usage of evaluate() would probably be a >> deal-breaker since it would be less expensive to perform the loop. >> >> Here's examples of what i'm trying to do: >> >> <!--- Trying to use backref passed as struct key ---> <cfset pageOut >> = reReplace(pageContent,"<%show:([a-zA-Z0-9_]+) >> %>",appSettings["\1"],"ALL")/> >> >> <!--- Trying to use backref passed as argument ---> <cfset pageOut = >> reReplace(pageContent,"<%getModule:([a-zA-Z0-9_]+) >> %>",controller.getModule("\1"),"ALL")/> >> >> Thoughts? >> >> Jon >> >> >> > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| 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:293454 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

