Daniel Shahaf wrote on Tue, 17 Dec 2019 01:55 +00:00: > I suppose that simply trying to repeatedly s/\s+\S+$// might work well > enough? That is:
In English: remove all non-whitespaces at the end of the string, then remove all trailing whitespace. > data = line[len('--- '):].rstrip('\n') > need_confirmation = False > while len(data) > 0: > if exists(data): > break > else: > data =~ s/\s+\S+$//; > need_confirmation = True > else: > raise Exception("{!r} does not exist".format(line[4:])) > if need_confirmation: > prompt_for_confirmation(data) >