count the match of a pattern