<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def findnextmatch(self, startkey, find_string, flags, search_result=True):
 """ Returns a tuple with the position of the next match of find_string Returns None if string not found. Parameters: startkey: Start position of search find_string:String to be searched for flags: List of strings, out of ["UP" xor "DOWN", "WHOLE_WORD", "MATCH_CASE", "REG_EXP"] search_result: Bool, defaults to True \tIf True then the search includes the result string (slower) """


        assert "UP" in flags or "DOWN" in flags
        assert not ("UP" in flags and "DOWN" in flags)

        if search_result:
            def is_matching(key, find_string, flags):
                code = self(key)
                if self.string_match(code, find_string, flags) is not None:
                    return True
                else:
                    res_str = unicode(self[key])
                    return self.string_match(res_str, find_string, flags) \
                        is not None

        else:
            def is_matching(code, find_string, flags):
                code = self(key)
                return self.string_match(code, find_string, flags) is not None

        # List of keys in sgrid in search order

        reverse = "UP" in flags

        for key in self._sorted_keys(self.keys(), startkey, reverse=reverse):
            try:
                if is_matching(key, find_string, flags):
                    return key

            except Exception:
                # re errors are cryptical: sre_constants,...
                pass