def _decode_v2(value):
    """
    Decode ':' and '$' characters encoded by `_encode`.
    """
    if re.search(r'(?<!\$):', value):
        raise ValueError("Unescaped ':' in the encoded string")

    decode_colons = value.replace('$:', ':')

    if re.search(r'(?<!\$)(\$\$)*\$([^$]|\Z)', decode_colons):
        raise ValueError("Unescaped '$' in encoded string")
    return decode_colons.replace('$$', '$')