Files
freecodecamp--freecodecamp/curriculum/challenges/english/blocks/daily-coding-challenges-python/68cae5b538ff798bbd4da004.md
T
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

1.7 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
68cae5b538ff798bbd4da004 Challenge 66: HTML Tag Stripper 29 challenge-66

--description--

Given a string of HTML code, remove the tags and return the plain text content.

  • The input string will contain only valid HTML.
  • HTML tags may be nested.
  • Remove the tags and any attributes.

For example, '<a href="#">Click here</a>' should return "Click here".

--hints--

strip_tags('<a href="#">Click here</a>') should return "Click here".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(strip_tags('<a href="#">Click here</a>'), "Click here")`)
}})

strip_tags('<p class="center">Hello <b>World</b>!</p>') should return "Hello World!".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(strip_tags('<p class="center">Hello <b>World</b>!</p>'), "Hello World!")`)
}})

strip_tags('<img src="cat.jpg" alt="Cat">') should return an empty string ("").

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(strip_tags('<img src="cat.jpg" alt="Cat">'), "")`)
}})

strip_tags('<main id="main"><section class="section">section</section><section class="section">section</section></main>') should return sectionsection.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(strip_tags('<main id="main"><section class="section">section</section><section class="section">section</section></main>'), "sectionsection")`)
}})

--seed--

--seed-contents--

def strip_tags(html):

    return html

--solutions--

import re
def strip_tags(html):
    return re.sub(r'<[^>]*>', '', html)