# Part 2: use re.match to match the entire html string, and extract data within the title.
m = re.match(r"^.*<title>\s*(.+?)\s*</title>.*$", html)
# Part 3: return the first group if match was successful.
return ""# Part 1: specify html string and get its title.
html = r"<html><title>Example.</title><body><p>...</p></body></html>"
print("TITLE:", gettitle(html))TITLE: Example.
In HTML, titles often contain important information about pages. And with Python we are often tasked with processing data files (which might involve their titles).
Summary. HTML can often be invalid, or may contain commented-out HTML. This is difficult for re.match to deal with—but often it has enough power to capture text.
Dot Net Perls is a collection of tested code examples. Pages are continually updated to stay current, with code correctness a top priority.
Sam Allen is passionate about computer languages. In the past, his work has been recommended by Apple and Microsoft and he has studied computers at a selective university in the United States.