kattaprasanth kattaprasanth - 1 year ago 105
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:

Answer Source

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).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download