keep=True defeats the purpose of a caching strategy. An re.compile call within some code somewhere is typically not in a position to know if it is going to be called a lot.
I think the code, as things are now, with dynamic construction at runtime based on a simple test is the best of both worlds to avoid the more complicated cost of calling re.compile and going through its cache logic. If the caching is ever is improved in the future to be faster, the code can arguably be simplified to use re.search or re.match directly and rely solely on the caching.
ie: don't change anything.