I'm not very good at regular expressions, but the following quick and dirty search and replace expressions should work:
Seach for:
Code:
<h2 id="([^"]+)" class="chapter"><span class="bold"><a id="([^"]+)"/>([^<]+)</span></h2>
Replace with:
Code:
<a id="\2"/><h2 id="\1" class="chapter"><span class="bold">\3</span></h2>