router: optimise matching by avoiding regexes

Try a pessimistic approach to see if we need to do regex matching.  If
not, we can resort to ordinary string comparisons, which are cheaper.