import re


def _strip_build_number(api_version):
  """Removes the build number component from a full api version string."""
  match = re.match(r"^([A-Z]+-)?([0-9]+)(\.[0-9]+){2}$", api_version)
  if match:
    return api_version[:match.start(3)]
  # if there aren't exactly 3 version number components, just leave it unchanged
  return api_version