> Another alternative, used by lots of languages/libraries, is to maintain a cache of recently compiled regular expressions. Of course, this doesn't help when you have a loop that uses 15 regular expressions but it only caches the last 14, for example.
Nitpick: it depends on the replacement policy whether it helps. If the cache is MRU, for example, it would work fine.
It doesn't matter if each one is used once, say in a loop.
If you have 14 slots in your cache, and you loop over 15 regular expressions, no cache policy (unless it also tracks regexes it has already lost from the cache, which effectively gives it more than 14 slots) will work, except maybe some kind of cache that just remembers the first 14 regexes it sees, and only forgets one randomly every 10 more regexes it sees. Such a cache policy would be really really stupid in most cases not specifically designed to thwomp, say, an LRU cache or a regular deque or something.
Nitpick: it depends on the replacement policy whether it helps. If the cache is MRU, for example, it would work fine.