Regex optimization: check prefix before applying regex