Convert slow lookups to regex