import re


def remove_special_characters(value: str) -> str:
  """Replaces special characters with '_' while keeping instances of '__'."""
  normalized_parts = []
  for part in value.split("__"):
    part = re.sub(r"[^a-zA-Z0-9_]", "_", part)  # Remove special characters.
    part = re.sub(r"_+", "_", part)  # Remove duplicate "_".
    part = part.strip("_")  # Don't end or start in "_".
    normalized_parts.append(part)
  return "__".join(normalized_parts)