def METHOD_NAME(name, pattern, backref):
    """Capture pattern to name or match back-reference to name
    >>> _capture_regex("run", "[0-9]+", False)
    '(?P<run>[0-9]+)'
    >>> _capture_regex("run", "[0-9]+", True)
    '(?P=run)'
    >>> re.match(_capture_regex("run", "[0-9]+", False), "123_").groupdict()
    {'run': '123'}
    """
    return f"(?P={name})" if backref else f"(?P<{name}>{pattern})"