<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _match_directories(self, entries, root, regex_string):
 """ Match directory names in paged hierarchies. Example: :: root = /foo/bar regex_string = [0-9]+ /foo/bar/ 1/ bar baz 2/ bar 3/ foo => ["/foo/bar/1", "/foo/bar/2", "/foo/bar/3"] :param list entries: the list of entries (paths) of a container :param string root: the root directory to search within :param string regex_string: regex string to match directory names :rtype: list of matched directories """

        self.log(u"Matching directory names in paged hierarchy")
        self.log([u"Matching within '%s'", root])
        self.log([u"Matching regex '%s'", regex_string])
        regex = re.compile(r"" + regex_string)
        directories = set()
        root_len = len(root)
        for entry in entries:
            # look only inside root dir
            if entry.startswith(root):
                self.log([u"Examining '%s'", entry])
                # remove common prefix root/
                entry = entry[root_len + 1:]
                # split path
                entry_splitted = entry.split(os.sep)
                # match regex
                if ((len(entry_splitted) >= 2) and
                        (re.match(regex, entry_splitted[0]) is not None)):
                    directories.add(entry_splitted[0])
                    self.log([u"Match: '%s'", entry_splitted[0]])
                else:
                    self.log([u"No match: '%s'", entry])
        return sorted(directories)