kattaprasanth kattaprasanth - 2 months ago 12
Python Question

Python regular Expression to get text between two strings

when i read a text, i have string like

<h3 class="heading">General Purpose</h3>
in some of the lines of the text, now i want to get only value that is
General Purpose
from above..

d = re.search(re.escape('<h3 class="heading">')+"(.*?)"+re.escape('</h3>'), str(data2))
if d:


Group 0 contains the entire match; you want the contents of group 1:


But generally, using regexes to parse HTML is not such a good idea (although practically speaking, nested h3 tags should be rather uncommon).