I think I understand what you're doing with that regex. The only issue is that Calibre doesn't support lower-casing via \L\E. But, I worked around that with the Calibre Editor's Regex-Funtion "Lower-case text" mode. I've got to examine the document a bit more to double-check, but it looks good. Thanks.
- Pass 1: Removes the extraneous starting bit of the bad chapter heading
- Pass 2: Grabs the end-of-word fragment, strips the formatting, makes it lower case with \L and \E (Calibre doesn't support that) and marks it as heading level h4
- Pass 3: Grabs the starting character, strips the formatting and marks it as heading level h3
- Pass 4: Grabs the end-of-word fragment at the h4 level, strips off everything else, concatenates it with the starting character at the h3 level and ends the result in an ending h3 tag
- Pass 5: Replaces each chunk of intermediate white space (and tags) with a single space
- Pass 6: Removes the intervening tags/whitespace/class="whitespace" stuff from between the remaining two strings and puts the second string in a span
- Pass 7: Removes the extraneous ending bit of the bad chapter heading