How to cover all case of <strong> <em> <u>
to <strong>
with python and smart way?
I was trying code to cover that but I think my way not good and have a lot of case.
Have any want know how to do that with better?
I very want have 2 way to learn that:
- Way 1: Not use regex.
- Way 2: Use regex.
My code now:
html = '''
<h1>Make bakery</h1>
<p>Step 1: Please use good quality product for make <strong><em>bakery</em></strong></p>
<p>Step 2: Make <em><u>bakery</u></em> hot</p>
<p>Step 2: Make <em><strong><u>bakery</u></strong></em> hot</p>
'''
def function_cover_all_strong(html):
html = html.replace('<u><em><strong>','<strong>')
html = html.replace('</strong></em></u>','</strong>')
html = html.replace('<em><strong><u>','<strong>')
html = html.replace('</u></strong></em>','</strong>')
html = html.replace('<strong><u><em>','<strong>')
html = html.replace('</em></u></strong>','</strong>')
html = html.replace('<strong><em><u>','<strong>')
html = html.replace('</u></em></strong>','</strong>')
html = html.replace('<em><u>','<strong>')
html = html.replace('</u></em>','</strong>')
html = html.replace('<u><strong>','<strong>')
html = html.replace('</strong></u>','</strong>')
html = html.replace('<u><em>','<strong>')
html = html.replace('</em></u>','</strong>')
html = html.replace('<strong><u>','<strong>')
html = html.replace('</u></strong>','</strong>')
html = html.replace('<strong><em>','<strong>')
html = html.replace('</em></strong>','</strong>')
html = html.replace('<u>','<strong>')
html = html.replace('</u>','</strong>')
html = html.replace('<em>','<strong>')
html = html.replace('</em>','</strong>')
return html
html_cover = function_cover_all_strong(html = html)
print(html_cover)
Thanks for your support! All best with you. I very try to research more but not see case like that!