REReplaceNoCase


hi,

thanks helping me. kinda trying write reg. expressions , not working well.

i have script trying read in cf , change variables , usage.

in following script/variable list want replace variable (i.e., lx) m1 , lx m2...
i want write reg. expression replace on these conditions

if varaible preceded space or comma or open paren ("(")
or if varibale followed space or comma or close paren (")")

i want replace in outstr variables replaced if string outside quotes.

thanks 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>




i'm kind of confused post, , variable names. however, i'm sure it's possible.

first off, why using rereplace when aren't doing regular expressions? can replacenocase() looks you're doing.

now, see you're doing, can show me typical input, , hope turn into? talk of inserting parentheses kind of confusing. if it's kinda reads like, maybe can add after 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")>


More discussions in Advanced Techniques


adobe

Comments

Popular posts from this blog

opencv3, tbb and rasp pi 2 - Raspberry Pi Forums

small ethernet problem - Raspberry Pi Forums

Multithumb configuration params not working? - Joomla! Forum - community, help and support