QUESTION 6
Markup languages allow us to annotate documents to identify their elements, and we can exploit these annotations in pattern-matching code to efficiently extract specific elements from such documents. The exercises and assessment items in this unit have often required matching patterns in this way.
An HTML document is available at this link: abbreviations.html. You should download this document as a local file to your computer and examine its source code, either using your web browser's "developer" options or a plain text editor such as Notepad or TextEdit. Your task is to develop a regular expression which matches specific elements in this document's source code.
Assume that the contents of this file have been assigned to a Python string-valued variable called web_document either by copying the source code text into the Python program as a character string or by reading it from the file, e.g., web_document = open(filename).read()
Now consider the following call to the findall function from Python's re module.
findall(regex, web_document)
Write a Python string to replace the placeholder regex above so that this function call returns the following list of matches from the web document, and no others. The elements of interest are text in list items that is underlined.
['ASCII', 'HTML']
Each matching element returned must contain all the text as shown above but must not contain any additional characters at either end. Your solution must not be hardwired to return these specific results from the sample web document only, but must work for any elements matching the description above in any similarly-formatted HTML document.
Enter your regular expression in the text box below.