Caching intermediate regular expressions