from typing import Pattern


def get_first_match(pattern: Pattern, string: str) -> str:
    """Return the first matching substring.

    Args:
        pattern: The pattern to find.
        string: The string to search.

    Returns:
        The first occurence of the pattern in the string.

    Raises:
        ValueError if the string does not match the pattern.
    """
    match = pattern.match(string)
    if match is None:
        raise ValueError("String '{}' does not match the pattern '{}'"
                         .format(string, pattern.pattern))
    return match.group(1)