from typing import Dict
import re


def _parse_mods(peptide: str) -> Dict[int, float]:
    """
    Parse a modified peptide string.

    Parameters
    ----------
    peptide : str
        The peptide string with modification indicated in square
        brackets.

    Returns
    -------
    Dict[int, float]
        The modifications for spectrum_utils.
    """
    mods = re.finditer(r"\[(.+?)\]", peptide)
    mod_dict = {}
    offset = 0
    for mod in mods:
        position = mod.start() - offset
        mod_dict[position] = float(mod.groups(1)[0])
        offset += mod.end() - mod.start()

    return mod_dict