from typing import Optional
from typing import Tuple
import re


def init_renumbering(renumber_group: Optional[str] = None) -> Tuple[Optional[int], int]:
    """Return renumber match group and renumber offset to use.

    Parse a renumbering format string of the form N(+|-)M and return the match
    group N and positive or negative offset M. For example, 2-10 would return
    match group 2 with offset -10.

    """
    if not renumber_group:
        return None, 0
    m = re.match(r"([0-9]+)(?:(\+|-)([0-9]+))?", renumber_group)
    if not m:
        raise ValueError(f"Invalid renumbering match group format: {renumber_group}")
    g = m.groups()
    renumber_match_group = int(g[0])
    renumber_offset = 0
    if g[1] == "+":
        renumber_offset = int(g[2])
    elif g[1] == "-":
        renumber_offset = 0 - int(g[2])
    return (renumber_match_group, renumber_offset)