A better find and replace function

Scott Rossi scott at tactilemedia.com
Thu Sep 28 10:10:10 EDT 2006


Recently, Robert Sneidar wrote:

> This may interest some of you. You may have stumbled across something
> with the replace command. Let's say I have a chunk that contains the
> word "blah". I want to replace all occurrences of "blah" with
> "noblah" which those of you who are astute see contains the word it
> replaces. If I call the replace command once, all my "blah"'s become
> "noblah"'s okay, but if I execute the command again, my noblahs
> become nonoblahs.
> 
> What I needed was something that would replace the WORD blah with the
> WORD noblah, ignoring words that CONTAIN blah, including subsequent
> search and replace executions. In other words I needed a whole word
> search and replace that only did it once per occurrence of a whole
> word (in the true sense of the "word" ) no matter how many times I
> ran it. I mainly need it for renaming function and command calls in a
> script, but it could be useful elsewhere.
> 
> Just do a wordoffset you say? Oh but nay, because wordoffset will hit
> on blah, noblah, blahse etc. I ONLY want the whole word blah, even if
> it is a function like say blah(). (Revolution thinks "blah
> (somearg,somearg2)" is all one word. :-) It's a lot harder than you
> might think, because Revolution's word offset is very liberal when it
> comes to what it thinks is a word.

I believe you can use the wholeMatches property to do what you need.
Setting the wholeMatches to true will force Rev to find wordOffsets of
"blah" while ignoring "noblah" and "blahse".

Regards,

Scott Rossi
Creative Director
Tactile Media, Multimedia & Design
-----
E: scott at tactilemedia.com
W: http://www.tactilemedia.com





More information about the Use-livecode mailing list