remote: reorganize check_pattern_match()