Optimize regex performance