Speed up the regex matching