fix the match group detection

The match group count detection fails whenever there is no matched group since the `match.lastindex` is  `None` actually, `None` can't be compared with `int`.