code: def get_s3_region_from_endpoint(endpoint):
      
  
      # Extract region by regex search.
      m = _EXTRACT_REGION_REGEX.search(endpoint)
      if m:
          # Regex matches, we have found a region.
          region = m.group(1)
          if region == 'external-1':
              # Handle special scenario for us-east-1 URL.
              return 'us-east-1'
          if region.startswith('dualstack'):
              # Handle special scenario for dualstack URL.
              return region.split('.')[1]
          return region
  
      # No regex matches return None.
      return None
docs: Extracts and returns an AWS S3 region from an endpoint
      of form `s3-ap-southeast-1.amazonaws.com`
  
      :param endpoint: Endpoint region to be extracted.