Greedy vs Lazy: Strip Bold Tags

Hard ⏱ 18 min 31% acceptance ★★★★★ 4.9
Given '<b>one</b> and <b>two</b>', the greedy pattern <b>.*</b> swallows everything between the FIRST <b> and LAST </b>. Write bold_texts(html) that correctly extracts each bold span's inner text using the lazy quantifier .*?.

Examples

Example 1
Input
bold_texts('<b>one</b> and <b>two</b>')
Output
['one', 'two']
Explanation

The lazy .*? stops at the nearest closing tag.

Constraints

  • Must use a lazy quantifier.
  • Return the inner texts only.

Topics

Regular Expressionslazy quantifiers

Companies

GoogleMozillaAdobe

Hints

Hint 1

r'<b>(.*?)</b>'.

Hint 2

Greedy .* would return one merged wrong match — try it to see.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.