router_rewrite_metric: prepare for more generic use

For aggregations with name capture groups, we need the same
functionality as rewriting metrics, so prepare for reuse.