There's also a Canonize feature in BBEDit that I'd never used that serves a possibly related mission.
Here's an example.
I'm completely smitten with a word processor called Mellel. It's my voice, rod, staff, and that magical fount from which prose flows.
In another forum, someone asked how to make table of contents entries appear one way in the manuscript and another way in the TOC in a Mellel document.
Generated tables of content are just editable text, so problem half solved there. Create the heading entries (auto-titles, in Mellel-speak) the way you want them to appear in the manuscript, generate a fresh TOC, and then hand-edit to suit your tastes.
But there's a problem. We're enlightened and highly evolved. We don't do hand edits.
BBEdit will open zip files and you can make edits in zip component files without manually zipping and unzipping. Mellel documents are actually zip format. The text portions of a document are in a component file called main.xml.
Auto-titles in Mellel are like headings with multiple formats. One format sets how they look in the manuscript, another in the TOC, and there are other formats for other contexts, like "mentions" in page footers.
A typical TOC format will have the chapter or section title followed by a tab. As stored in the document file that appears as the chapter title followed by a keyword.
BBEdit's Canonize takes a file formatted as "search string tab-character replacement string", where tab-character is an ASCII tab, decimal 9.
So, a file with lines consisting of "actual title keyword tab-character shortened TOC title" will find the chapter titles in the generated TOC but not in the manuscript and translate them as desired.
BBEdit is truly cool.