import re


def dict_from_regex_match(pattern, input_, type_dispatcher=None):
    """Return a dict from matching `pattern` to `input_`.

    If match failed, returns None.

    Parameters
    ----------
    pattern : str, `re.Pattern`
        The regex that matches to the `input_`.

    input_ : str
        The string to be matched.

    type_dispatcher : dict
        This specifies how the matched group values are handled after being
        extracted.
    """
    if type_dispatcher is None:
        type_dispatcher = dict()
    m = re.match(pattern, input_)
    if m is None:
        return None

    result = dict()

    for k, v in m.groupdict().items():
        if k in type_dispatcher:
            result[k] = type_dispatcher[k](v)
        else:
            result[k] = v
    return result