wildcard-matching: iterative algorithm