Fixed error in parsing regex groupings, and added more extensive regex error handling.