def search_backwards(text, start_point, limit, pattern):
    """Search the range [limit, start_point] for instances of |pattern|.
    Returns the one closest to |start_point|.
    Returns |limit| if none are found."""
    assert limit < start_point
    matches = list(pattern.finditer(text[limit:start_point]))
    if len(matches) == 0:
        return limit
    return limit + matches[-1].start(0)