Write three regular expressions that will be passed to re.sub() in order to modify the body element in our HTML file:
body_insert that will be used to add elements immediately after the body element opening tag: <body>.body_append that will be used to add elements immediately before the body element closing tag: </body>.body_rewrite that will be used to replace the content of the body element: <body>content</body>.Details to take into account:
<body> will be followed by line break \n, you should match after the line break.</body> will be preceded by line break \n, you should match before the line break.body_rewrite should match the content of the body element, but not the body tags.index = '''
<body>
<p>This is a paragraph and <a href="https://innokodakademija.com">this is a link</a>.</p>
</body>
'''
body_insert = "yourregularexpressionhere"
body_append = "yourregularexpressionhere"
body_rewrite = "yourregularexpressionhere"
re.sub(body_insert, ' <p>Pre-Paragraph</p>\n', index) ➞
'''
<body>
<p>Pre-Paragraph</p>
<p>This is a paragraph and <a href="https://innokodakademija.com">this is a link</a>.</p>
</body>
'''
re.sub(body_append, '\n <p>Post-Paragraph</p>', index) ➞
'''
<body>
<p>This is a paragraph and <a href="https://innokodakademija.com">this is a link</a>.</p>
<p>Post-Paragraph</p>
</body>
'''
re.sub(body_rewrite, ' <p>Anti-Paragraph</p>', index) ➞
'''
<body>
<p>Anti-Paragraph</p>'
</body>
'''
You don't need to write a function, just the pattern.
Do not remove import re from the code.
If you get stuck, check Comments for some helpful hints.
You can find all the challenges of this series in my Basic RegEx collection.