import re


def get_valid_filename(s):
    """Sanitize string to make it reasonable to use as a filename.

    From https://github.com/django/django/blob/master/django/utils/text.py

    Parameters
    ----------
    s : string

    Examples
    --------
    >>> print get_valid_filename(r'A,bCd $%#^#*!()"\' .ext ')
    'a_bcd__.ext'

    """
    s = re.sub(r'[ ,;\t]', '_', s.strip().lower())
    return re.sub(r'(?u)[^-\w.]', '', s)