For more elegant code, we should compile the regular expression outside the for loop with re.compile so it only needs to be done once.