Matchtext for multiple words
Brian Yennie
briany at qldlearning.com
Wed Nov 29 17:37:53 EST 2006
Jacque,
I think the "in any order" part will make a single RegEx a nightmare
(although it's probably technically possible).
How about using something simple like (or scroll down for a non-RegEx
idea)
".*(dinosaur|dog|cat).*"
Then capture the actual text matched, and remove that from the
expression. So in your example, you would first match "dinosaur".
Then you would run the RegEx again as:
".*(dog|cat).*"
Which would match "cat".
Then finally:
".*dog.*"
If you're not married to RegEx, you could just do something like
this. It should be pretty speedy, as it uses array lookups, simple
comparisons, and only one pass through your text.
## put the words into an array for quick lookup
repeat for each word w in wordList
put 0 into myWords[w]
end repeat
## loop through your text and mark all of the words you find
repeat for each word w in myText
if (myWords[w] = 0) then
put 1 into myWords[w]
end if
end repeat
## check that all of your words were "marked" with a 1
put TRUE into foundThemAll
repeat for each word w in wordList
if (myWords[w] <> 1) then
put FALSE into foundThemAll
exit repeat
end if
end repeat
> Sorry if this comes through twice, I'm having trouble sending to
> the list.
>
> 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?
>
> --
> Jacqueline Landman Gay | jacque at hyperactivesw.com
> HyperActive Software | http://www.hyperactivesw.com
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
>
>
More information about the use-livecode
mailing list