from typing import Match
import re


def test_replacement_function() -> None:
    """Search and replace using a replacement function."""

    def hexrepl(match: Match[str]) -> str:
        """Return the hex string for a decimal number."""
        return hex(int(match.group()))

    assert (
        re.sub(r"\d+", hexrepl, "65490: printing, 49152: user code")
        == "0xffd2: printing, 0xc000: user code"
    )