'Filter out directives with specific number of arguments.
This function makes the assumption that all related arguments are given
in order.  Thus /files/apache/directive[5]/arg[2] must come immediately
after /files/apache/directive[5]/arg[1]. Runs in 1 linear pass.
:param string matches: Matches of all directives with arg nodes
:param int args: Number of args you would like to filter
:returns: List of directives that contain # of arguments.
(arg is stripped off)'

def filter_args_num(self, matches, args):

    filtered = []
    if (args == 1):
        for i in range(len(matches)):
            if matches[i].endswith('/arg'):
                filtered.append(matches[i][:(-4)])
    else:
        for i in range(len(matches)):
            if matches[i].endswith(('/arg[%d]' % args)):
                if ((i == (len(matches) - 1)) or (not matches[(i + 1)].endswith(('/arg[%d]' % (args + 1))))):
                    filtered.append(matches[i][:(- len(('/arg[%d]' % args)))])
    return filtered
