in reply to Re: regex matching using arrays
in thread regex matching using arrays

Cool, thanks zejames.
Do you know if there is a limit on the size that $regex can take? i.e. if the array is really big will it break things?

Replies are listed 'Best First'.
Re^3: regex matching using arrays
by BUU (Prior) on Dec 04, 2004 at 11:34 UTC
    Your regex will extend up to the maximum size of your scalars.. which can go past the size of your physical memory! However, I'm sure after a few hundred OR clauses the regex will get bloody slow. You should probably bench it.
Re^3: regex matching using arrays
by ikegami (Patriarch) on Dec 05, 2004 at 17:34 UTC
    Of course, that loops over the array twice (map and join)
Re^3: regex matching using arrays
by graff (Chancellor) on Dec 08, 2004 at 03:52 UTC
    Do you know if there is a limit on the size that $regex can take? i.e. if the array is really big will it break things?
    If you have a large word list, and you're trying to determine which of those words occur in a given text of arbitrary length, the best approach is likely to be to store the word list in a hash, then tokenize the text string; for each tokenized word in the string, if that word exists as a hash key, you've got a hit (append that word to your output list).

    This way, you've got one simple loop over the "lexicon" (to store the word list as hash keys), and one loop over the word tokens in the text string; you're doing plain string comparisons (best to put everything in monocase) instead of regex matches, so it should be pretty quick.