that will do what you want:
<cfscript>
function REFindAndReplace(string,regexp,substring){
var caseSensitive = true;
var scope = "one";
var returnSubexpressions = false;
var stReturn = StructNew();
var stTmp = StructNew();
var aTmp = ArrayNew(1);
var i = 1;
var start = 1;
// optional arguments
// 4th argument: case sensitivity
if(ArrayLen(arguments) GE 4) caseSensitive = arguments[4];
// 5th argument: scope "one" or "all"
if(ArrayLen(arguments) GE 5) scope = arguments[5];
// 6th argument: return subexpressions in matches
if(ArrayLen(arguments) GE 6) returnSubexpressions =
arguments[6];
// replace expressions
if(caseSensitive)
stReturn.string =
REReplace(string,regexp,substring,scope);
else
stReturn.string =
REReplaceNoCase(string,regexp,substring,scope);
stReturn.match = ArrayNew(1);
// find matches for expressions
while(true){
if(caseSensitive)
stTmp = REFind(regexp,string,start,true);
else
stTmp = REFindNoCase(regexp,string,start,true);
if(stTmp.pos[1] IS 0) break;
if(returnSubexpressions){
aTmp = ArrayNew(1);
for(i=1;i LE ArrayLen(stTmp.pos);i=i+1){
ArrayAppend(aTmp,Mid(string,stTmp.pos[i],stTmp.len[i]));
}
ArrayAppend(stReturn.match,aTmp);
}
else{
ArrayAppend(stReturn.match,Mid(string,stTmp.pos[1],stTmp.len[1]));
}
if(scope NEQ "all") break;
start = stTmp.pos[1] + stTmp.len[1];
}
return stReturn;
}
</cfscript>
<cfsavecontent variable="txt">
It searches for e.g. {img123} and replaces something like {img456} by
Image 456.
{img123}
</cfsavecontent>
<cfoutput><pre>#txt#</pre></cfoutput>
<cfdump var="#REFindAndReplace(txt,'\{img([[:digit:]]+)\}','Image
\1',false,'all',true)#">
Pascal
> Here's what I have now. It searches for e.g. {img123} and
> replaces it with Image 123.
>
> #REReplaceNoCase(Form.Text, "\{img([[:digit:]]+)\}", "Image
> \1", "All")#
>
> How do I extract the 123 portion to be used for another purpose?
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

