code: def NonNegIntStringToInt(int_string, problems=None):
    
    # Will raise TypeError unless a string
    match = re.match(r"^(?:0|[1-9]\d*)$", int_string)
    # Will raise ValueError if the string can't be parsed
    parsed_value = int(int_string)
  
    if parsed_value < 0:
      raise ValueError()
    elif not match and problems is not None:
      # Does not match the regex, but it's an int according to Python
      problems.InvalidNonNegativeIntegerValue(int_string)
  
    return parsed_value
docs: Convert an non-negative integer string to an int or raise an exception