Allow prefixes to be regexes or captures.

Ref #966 - changes to allow, capture strings and regexes in prefixes.

There is at least one edge case bug (see the test).. feel free to not to merge if you'd rather those were addressed.