shot in the dark here but... couldn't you just use regex to split up the host name and just replace the back references with a wildcard?