import re


def newstyle_serial(name):
    """Return the serial number associated with a CRDS-style name.

    >>> newstyle_serial("hst_0042.pmap")
    42
    >>> newstyle_serial("hst_0990999.pmap")    
    990999
    >>> newstyle_serial("hst_cos_0999.imap")
    999
    >>> newstyle_serial("hst_cos_darkfile_0998.fits")
    998
    >>> newstyle_serial("hst.pmap")
    -1
    """
    assert isinstance(name, str)
    serial_search = re.search(r"_(\d+)\.\w+", name)
    if serial_search:
        return int(serial_search.groups()[0], 10)
    else:
        return -1