replacing only exact matches in script

Dr. Hawkins dochawk at gmail.com
Wed Aug 7 15:10:24 EDT 2019



I’m finally writing my new version of dependency calculation for database variables, with a supposedly clever easy format fo entry and machine calculated script.

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.

I can’t with any certainty control the order that variables will appear in my ”raw” formulae (too many ways to blow up!).

I’ve considered requiring a space before and after, but, again, two many ways to blow up.

I could manually parse the line, looking for starts and stops, but it’s both ugly and asking for obscure bugs.

I could make a list of all the truewords, and cycle through, moving any one that is a substring of any other to the end, and repeatedly looping until the list is empty.  Ugly, but the least insane of the options I’ve come up with.

I can handle a performance penalty, as this routine would run only in the development version, with the resultant array saved as a stack property in any shipped version. But I’d still like it to be as fast as I can and avoid thumb-twiddling . . .
— 
Richard E. Hawkins, Esq.
The Hawkins Law Firm
3430 E. Flamingo Rd.
Suite 232
Las Vegas, NV  89121
(702) 508-8462




More information about the use-livecode mailing list