Using pattern matching for routing