I'm moving and cleaning up a website (about 40k pages) I took over maintence of that has several problems. Some people on a forum recommended I check out text pipe for some of the things I needed to do. So far many of the problems I have appear to be correctable with text pipe, but I don't see how to do one of the really major cleanup tasks I have.

the ../www.website.com/ and index.htm part of the URLs is constant but the rest is variable and there's several thousand different variations of the code that falls between them. What I want to do is drop everything but the /####/index.htm#xxxx to make simple relative links. So the examples above would eventually become something (I can easily adjust the paths and such after the main URL cleanup is done) like:

But I don't see a way for text pipe to do it. I can get it to match the full URLs easily enough with
../www.website.com/[ longest 1 to 40 letters or digits or <!"#$%&'()*+,-./\:;=?@[]^_`{}~|> ]/[ longest 1 to 4 digits ]/index.htm[ longest 1 to 5 digits or letters or <!"#$%&'()*+,-./\:;=?@[]^_`{}~|> ]
But I don't see any way to get it to remove the preceeding code and leave the part I want to keep nor anyway to match the offending text and just remove it without the part I want to keep.