Calculate the match group id.