Some code to help map regular expression matches to objects