Here's my REG_STARTEND patch, mostly copied from the original tre[1] implementation.
It's only lightly tested.