import re


def parse_version_from_filename(filename):
    """Attempts to parse a version string from the filename of a Junos package.

    There is wide variety in the naming schemes used by Junos software
    packages. This function attempts to parse the version string from the
    filename, but may not be able to accurately do so. It's also not
    guaranteed that the filename of a package accurately reflects the version
    of software in the file. (A user may have renamed it.)
    If the filename does not appear to be a Junos package (maybe some other
    type of package which can be installed on Junos devices), then return None.

    Args:
        filename - The filename from which to parse the version string.

    Returns:
        The version string, or None if unable to parse.
    """
    # Known prefixes for filenames which contain Junos software packages.
    JUNOS_PACKAGE_PREFIXES = ['jbundle', 'jinstall', 'junos-install',
                              'junos-srx', 'junos-vmhost-install', 'junos-vrr',
                              'vmx-bundle']
    for prefix in JUNOS_PACKAGE_PREFIXES:
        if filename.startswith(prefix):
            # Assumes the version string will be prefixed by -.
            # Assume major version will begin with two digits followed by dot.
            # Assume the version string ends with the last digit in filename.
            match = re.search('-(\d{2}\..*\d).*', filename)
            if match is not None:
                return match.group(1)
    # Not a known Junos package name.
    else:
        return None