I have an HTML page that lists a long index of topics and page numbers. I want to find all the page numbers and their anchor tag links and decrement the page numbers by 1
.
Here is an example line in the HTML:
<p class="index">breakeven volume (BEV), <a href="ch02.xhtml#page28">28</a></p>
I'm trying to find the number 28
in both places and decrement by 1
.
So far I've been able to find the number and replace it with itself, but I can't figure out how to decrement it. My code so far:
import fileinput
import re
for line in fileinput.input():
line = re.sub(r'\>([0-9]+)\<', r'>\1<', line.rstrip())
print(line)