Skip to main content
September 10, 2006
Question

REReplaceNoCase

  • September 10, 2006
  • 1 reply
  • 338 views
hi,

thanks for helping me. i am kinda trying to write a reg. expressions and not working well.

i have a script where i am trying to read in CF and change its variables and its usage.

In the following script/variable list I only want to replace variable (i.e., LX) with M1 and LX with M2...
I want to write a Reg. Expression to replace on these conditions

if a varaible is preceded by a Space or a Comma or a Open Paren ("(")
or if a varibale is followed by a Space or a Comma or a Close Paren (")")

I also want to replace in OUTSTR variables replaced only if the string is outside the Quotes.

Thanks for your help.

Regards,
sc



<CFSET VARARRAY= ArrayNew(1)>
<CFSET CHGARRAY= ArrayNew(1)>

<CFSET VARARRAY[1] = "LX"> <CFSET CHGARRAY[1] = "M1">
<CFSET VARARRAY[2] = "LX2"> <CFSET CHGARRAY[2] = "M2">
<CFSET VARARRAY[3] = "RX"> <CFSET CHGARRAY[3] = "T1">
<CFSET VARARRAY[4] = "RX2"> <CFSET CHGARRAY[4] = "T2">

<CFSET CODESTR = "callFunction( LX, RX, LX2, RX2 )">

<CFLOOP INDEX = "DX" FROM=1 TO=4>
<CFSET CODESTR = REReplaceNoCase(CODESTR, VARARRAY[DX], CHGARRAY[DX]>
</CFLOOP>

<CFSET OUTSTR = 'print(" LX = ", LX, " LX2 = ", LX2, " RX = ", RX, " RX2 = ", RX2);'>

<CFOUTPUT>
#CODESTR# <br>
#OUTSTR#<br>
</CFOUTPUT>




This topic has been closed for replies.

1 reply

Participating Frequently
September 10, 2006
I'm kind of confused by your post, and your variable names. However, i'm sure it's possible.

First off, why are you using REReplace when you aren't doing any regular expressions? You can just do replaceNoCase() for what it looks like you're doing.

Now, to really see what you're doing, can you show me a typical input, and what you hope to turn that into? Your talk of inserting parentheses is kind of confusing. If it's what it kinda reads like, then maybe you can add something like this after your cfloop (untested, sorry)...

<!--- preceeding parentheses ( --->
<cfset codestr = reReplaceNoCase(codestr, "([\s,](lx|lx2|rx|rx2|m1|m2|t1|t2)[\s,])", "(\1", "ALL")>
<!--- trailing parentheses ( --->
<cfset codestr = reReplaceNoCase(codestr, "((lx|lx2|rx|rx2|m1|m2|t1|t2)[\s,])", "\1)", "ALL")>