I found a great solution and I would like to share. Fortunately the search/replace is done before the chapter detection, so all you have to do is search eg.
and replace with eg.
Code:
<h2>Chapter \1</h2>
. This way the chapters are properly found and converted.