import re


def unindent(string):
    """Remove the initial part of whitespace from string.

    >>> unindent("1 + 2 + 3\\n")
    '1 + 2 + 3'
    >>> unindent("  def fun():\\n    return 42\\n")
    'def fun():\\n  return 42'
    >>> unindent("\\n  def fun():\\n    return 42\\n")
    'def fun():\\n  return 42'
    >>> unindent("  def fun():\\n    return 42\\n\\n")
    'def fun():\\n  return 42'
    """
    string = re.sub(r'^\n*', '', string.rstrip()) # ignore leading and trailing newlines
    match = re.match(r'^([\t ]+)', string)
    if not match:
        return string
    whitespace = match.group(1)

    lines = []
    for line in string.splitlines(True):
        if line.startswith(whitespace):
            lines.append(line[len(whitespace):])
        else:
            return string
    return ''.join(lines)