<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def matchiter(r, s, flags=0):
 """ Yields contiguous MatchObjects of r in s. Raises ValueError if r eventually doesn't match contiguously. """

    if isinstance(r, basestring):
        r = re.compile(r, flags)
    i = 0
    while s:
        m = r.match(s)
        g = m and m.group(0)
        if not m or not g:
            raise ValueError("{}: {!r}".format(i, s[:50]))
        i += len(g)
        s = s[len(g):]
        yield m