def expect_re(regexp, buf, pos):
    """Require a regular expression at the current buffer position."""
    match = regexp.match(buf, pos)
    if not match:
        return None, len(buf)
    return buf[match.start(1):match.end(1)], match.end(0)