optimize regex match through use of cache.