Adding anchors to h2 in text using python and regexp
- by Oli
I'm trying to add anchors to all h2's in my html, using python. This code will add those anchors, but I need to fill the name of the anchors too.
Any idea if the name can be the number of the match in the loop or a slugified version of the text between the h2 tags?
Here's the code so far:
regex = '(?P<name><h2>.*?</h2>)'
text = re.sub(regex, "<a name=''/>"+r"\g<name>", text)