import re


def parse_query(lines, features=None):
    """
    Parse a query and returns the issued and used number of a given feature

    Parameters
    ----------
    lines : str
        Query result
    features : list[str] or None
        Feature names to extract (optional)
        If features is None, return all the features

    Returns
    -------
    dict(feature, tuple(int, int))
        Dictionary of feature name and a tuple of issued and used feature
    """
    def create_regexpr():
        s = r'[a-zA-Z][a-zA-Z0-9_-]*' if features is None else '|'.join(
            features)
        return re.compile(r'Users of (' + s + '):'
                          r'  \(Total of (\d+) licenses?? issued;'
                          r'  Total of (\d+) licenses?? in use\)')

    def to_tuple(match):
        feature = match[0]
        issued = int(match[1])
        used = int(match[2])
        return feature, (issued, used)

    reg = create_regexpr()
    matches = reg.findall(lines)
    return dict(map(to_tuple, matches))