Remove Ugly sed and update with Regex

Prior to this commit we had some ugly sed doing most of the work here.
We now replace that with a RE match goup which seems decent enough at
the moment