What I frequently do for this is to change to styled paragraphs and a separate heading for the ToC that is not displayed. So, I would have:
Code:
<h2 class="hidden">Chapter XX: Title of the Chapter</h2>
<p class="chapterNumber">Chapter XX</p>
<p class="chapterTitle">Title of the Chapter</p>
The stylesheet would need to appropriate classes to get the desired look. Including:
Code:
.hidden {
display: none
}
An alternative is:
Code:
<h2>Chapter XX <br/><span class="chapterSubtitle">Title of the Chapter<h2>
That has the advantage of only having the actual title once. But, I don't like that I need a space before the br tag for when calibre generates the ToC. It upsets the centring of the heading (someday I'll get around to looking at the code that does this, as I think the br should be replaced by a space). The first one is good is if you want the ToC to be different to the what is displayed. Such as might not want the word "Chapter" in the actual ToC and you can put a colon or dash between the parts. It is also good if you are using any graphics in the chapter title.
The regex search I would use is:
Code:
<h2>(.*?)</h2>\s*<h3>(.*?)</h3>
The replace for the first version is:
Code:
<h2 class="hidden">\1: \2</h2><p class="chapterNumber">\1</p><p class="chapterTitle">\2</p>
The replace for the second version is:
Code:
<h2>\1 <br/><span class="chapterSubtitle">\2<h2>
I tested the above using
https://regex101.com/ not the editor. If you have classes or identifiers in the heading tags, the regex needs to accommodate them. The versions that @DNSB posted come close. But, calibre doesn't use the "title" attribute for the ToC (or didn't the last time I tried).
And I'll go on record: I think that the method that @JSWolf suggested is a really, really bad idea.