def mask_digits_only(val: str, visible_count: int = 4) -> str:
# Find positions of all digits
digit_indices = [i for i, char in enumerate(val) if char.isdigit()]
# Identify which digit positions to mask (all except the last `visible_count`)
to_mask = set(digit_indices[:-visible_count])
return "".join("*" if i in to_mask else char for i, char in enumerate(val))
# Example Usage
formatted_card = "1234-5678-9012-3456"
print(mask_digits_only(formatted_card)) # Output: ****-****-****-3456
'''
run:
****-****-****-3456
'''