Matches patterns based on specific criteria.