Matchtext for multiple words
Dick Kriesel
dick.kriesel at mail.com
Wed Nov 29 19:00:17 EST 2006
On 11/29/06 1:39 PM, "J. Landman Gay" <jacque at hyperactivesw.com> wrote:
> I need a matchtext/regex that will tell me if all supplied words exist
> in a block of text, regardless of their order, and ignoring carriage
> returns.
>
> For example, see if all these words: dog dinosaur cat
>
> exist in this text:
>
> "The purple dinosaur inadvertently stepped on the cat.<cr>
> The white dog howled."
>
> Should return true. Is there such a thing?
Since Rev says "cat" and "cat." are different words, punctuation poses a
problem. Here's an approach that's simple and fast but depends on the
programmer to include a replace statement for each punctuation mark.
-- Dick
on mouseUp
put ""
put "The purple dinosaur inadvertently stepped on the cat." & cr \
& "The white dog howled." into tText
put "dog dinosaur cat" into tWords
putLines textContainsAllWords(tText,tWords)
end mouseUp
function textContainsAllWords tText,pWords
replace "." with space in tText
replace "," with space in tText
repeat for each word tWord in tText
put 1 into tArray[tWord]
end repeat
repeat for each word tWord in pWords
if tArray[tWord] is empty then return "false"
end repeat
return "true"
end textContainsAllWords
More information about the use-livecode
mailing list