Using str.index() instead of str.find() solution in Clear category for Between Markers by DreadBeard
def between_markers(text: str, begin:str='', end:str='') -> str:
#returns substring between two given markers
#If the initial and final markers are missing then simply return the whole string.
if begin == '' and end == '': return text
#If there is no initial marker, then the first character should be considered the beginning of a string.
if begin != '':
try: start = text.index(begin)+len(begin)
except ValueError: start = 0
else: start = 0
#If there is no final marker, then the last character should be considered the ending of a string.
if end != '':
try: stop = text.index(end)
except ValueError: stop = len(text)
else: stop = len(text)
#If the final marker comes before the initial marker, then return an empty string.
str.index() throws a ValueError when it can't match the given substring
str.find() returns -1 when it can't match the given substring
Nov. 12, 2018