Use the regex capturesdict() method to simplify the code