>Is it possible to dynamically evaluate the temp variable from the
>regular expression and use it as a ColdFusion variable?

It's not a "temp variable from the regular expression", it is a variable which 
exists *within the scope* of that regular expression.

That's important to understand - given this expression:

REReplaceNoCase(REQUEST.theURL, '%%(\w+)%%',
"#REQUEST.myQ[/\1][1]#", 'ALL')

The CF expression is evaluated *before* the regex does its stuff, and thus the 
\1 never enters the regex 'scope', and doesn't gets treated as a regex 
back-reference.

(hope that explanation makes sense?)

Depending on if/how you want to handle invalid columns, one solution which wont 
cause errors is to simply loop through the query column names, like so:

<cfset Request.Final = REQUEST.theURL />
<cfloop index="CurCol" list="#REQUEST.myQ.ColumnList#">
    <cfset Request.Final = 
replace(Request.Final,'%%#CurCol#%%',REQUEST.myQ[CurCol][1],'all') />
</cfloop>

That will mean that any mis-named columns are still in the string - so you may 
want/need to look for remaining %% in the string and behave appropriately.


But, going back to the regex solution for this - which can be more flexible, 
and is definitely worth knowing - the way to do this is to use a regex replace 
function which allows you to pass a function as the third argument.

Afaik none of the three main CFML engines allow this (yet), but I do have a CFC 
that enables assorted regex features, including passing a function:
http://hybridchill.com/projects/jre-utils.html

Once you've created the object (named jre below), you can then do:

<cfset REQUEST.final = jre.replace( REQUEST.theURL , '%%(\w+)%%' , MyFunction , 
'all' ) />

Then, you can create a function (see the "callback function" example at the 
above link) named MyFunction and return this:
<cfreturn REQUEST.myQ[ Arguments.Groups[1] ][1] />

And that should all ultimately work as you were going for initially.


Hopefully all this makes sense - let me know if any questions/etc. :) 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:330331
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