Optimized used of regexes