replacing only exact matches in script

hh hh at hyperhh.de
Wed Aug 7 17:32:31 EDT 2019


> Richard H. wrote:
> I need to replace only exact true words, though.
> So I need to be able to take an input string such as 
>    5*pay - 2*monthlypay
> and be able to replace “pay" with
>    getVal(pay,,,debtor)
> without  replacing monthlypay.

You could try the following (works for me).

Put a three-char string that's not in inString into X, e.g.

put "yap" into X

repeat for each line L in inString
  repeat while \
    matchChunk(L,"(?i)(^|\W)(pay)($|\W)",p1,p2,p3,p4,p5,p6)
    put X into char p3 to p4 of L -- replaces pay
  end repeat
  put cr & L after outString
end repeat
replace X with "getVal(pay,,,debtor)" in outString

This finds case-insensitive exactly the trueWord "pay".





More information about the use-livecode mailing list