Step 1: Open up the
Find/Replace (Ctrl+F) or press the menu
Search > Find & Replace.
Step 2: Make sure you have the
Mode box set as
Regex.
If you want to be safe, only have the Index open in Sigil, and change the 2nd dropdown to "Current File". This will make sure it won't go replacing through your entire book (although it shouldn't).
Step 3: Put this in the fields:
Search: <div class="sgc-index-entry">\s+(.+?)\s+(<a href="[^"]+">)\d+</a>\s+</div>
Replace: <div class="sgc-index-entry">\2\1</a></div>
What that will do is take your example code, and convert it into:
Code:
<div class="sgc-index-entry"><a href="link to the poem">first line of the poem</a></div>
It takes the link from around #1 and wraps it around the entry instead.
Alternate #3: Personally, what I would do is use:
Replace: <p class="indexfirstline">\2\1</a></p>
and adjust the CSS. The code would be much more readable.