import re
from typing import Literal


def extract_text(
    pattern: re.Pattern[str] | str,
    source_text: str,
) -> str | Literal[False]:
    """Match the given pattern and extract the matched text as a string."""
    match = re.search(pattern, source_text)
    if not match:
        return False
    match_text = match.groups()[0] if match.groups() else match.group()
    return match_text