Minor improvments to the regex matching