Use a single function to match names against patterns