Find matching modules using a package and a module name pattern.

def find_related_modules(package, related_name_re='.+',
                         ignore_exceptions=False):
    """Find matching modules using a package and a module name pattern."""
    warnings.warn('find_related_modules has been deprecated.',
                  DeprecationWarning)
    package_elements = package.rsplit(".", 1)
    try:
        if len(package_elements) == 2:
            pkg = __import__(package_elements[0], globals(), locals(), [
                             package_elements[1]])
            pkg = getattr(pkg, package_elements[1])
        else:
            pkg = __import__(package_elements[0], globals(), locals(), [])
        pkg_path = pkg.__path__
    except AttributeError:
        return []

    # Find all modules named according to related_name
    p = re.compile(related_name_re)
    modules = []

    for name in find_modules(package, include_packages=True):
        if p.match(name.split('.')[-1]):
            try:
                modules.append(import_string(name, silent=ignore_exceptions))
            except Exception as e:
                if not ignore_exceptions:
                    raise e

    return modules