added check for a matching capture group, preventing a crash