Moving re.compile out of functions has the potential to speed up re-intensive functions (although re.compile does cache results on its own).
Closes: #971960