Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
str.index() and exceptions catching solution in Clear category for Between Markers by t4d3uszk
def between_markers(text: str, begin: str, end: str) -> str:
"""
returns substring between two given markers
"""
try:
begin_pos = text.index(begin) + len(begin)
except ValueError:
begin_pos = 0
try:
end_pos = text.index(end)
except ValueError:
end_pos = len(text)
return text[begin_pos:end_pos]
July 18, 2019