import re


def extract_title(preamble_md):
    """Extract the title from preamble markdown.
    Returns None on failure."""
    # title regex: some number of hashes followed by a non-hash.
    regex = re.compile(b'^#+[^#]\s*(.*)$')
    for line in preamble_md.splitlines():
        m = regex.match(line)
        if m:
            title = m.group(1)
            return title
        else:
            continue
    return None