<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def filter_components(self, pattern, category=None):
 """ Filters the Components using given regex pattern. Usage:: True [u'core.tests_component_a'] :param pattern: Regex filtering pattern. :type pattern: unicode :param category: Category filter. :type category: unicode :return: Matching Components. :rtype: list """


        filtered_components = []
        for component, profile in self:
            if category:
                if profile.category != category:
                    continue

            if re.search(pattern, component):
                filtered_components.append(component)
        return filtered_components