regex to add a variable to calls

Thierry Douez th.douez at gmail.com
Mon Sep 19 13:42:11 EDT 2016


2016-09-17 0:13 GMT+02:00
Dr. Hawkins <dochawk at gmail.com>:

I need to catch every instance of
>
> getVal(a,b,c)
>
> and change them to
>
> getVal(a,b,c,dbtr)
>
> (and similarly to find when called with one or two arguments)
>
> dbtr is the variable name I want to pass.
>


​Here is one way to do it.


*on* mouseUp

*put* "getVal\([^)]+(?=\))" into theRegex

*put* "\0,dbtr" into smartReplaceText

*if* sunnyreplace( fld "f1", theRegex, smartReplaceText, outText) *then*

*put* outText into fld "f2"

*end* *if*

*end* mouseUp

​

​some sample input text in fld "F1" :

get getVal(a)

put getVal(a,b) into z

put getVal(a,b,c) && getVal(a,b,c) into y


and results in fld "f2":

get getVal(a,dbtr)

put getVal(a,b,dbtr) into z

put getVal(a,b,c,dbtr) && getVal(a,b,c,dbtr) into y


Is this what you are looking for?

Regards,

Thierry
​


------------------------------------------------
Thierry Douez - http://sunny-tdz.com
sunnYrex - sunnYtext2speech - sunnYperl - sunnYmidi - sunnYmage



More information about the use-livecode mailing list