Looks like you want to reset your notes numbering in every new chapter. Is that it?
Looking at your code, I can see that your identifiers already work like this, so it would be easy to achieve it using regex:
Find:
Code:
bodyftn(\d*?)">\d*?<
Replace:
The code you posted is from you endnotes. Now, you also have to change the notes in every chapter, so the numbering will match. The logic is the same, but I can't tell you the exact find/replace terms because you didn't post the code.