import re


def _replace_labels(html: str) -> str:
    """
    Replace Django's question-level labels with legend elements
    """
    return re.sub(
        "<fieldset><label [^>]+>(.*?)</label>",
        lambda m: f'<fieldset><legend class="tdp-question-legend">{m[1]}</legend>',  # noqa: B950
        html,
    )