Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First split split solution in Clear category for Between Markers (simplified) by LeonidPK
def between_markers(text: str, begin: str, end: str) -> str:
"""
returns substring between two given markers
"""
# 1. split text by begin marker as a separator
# 2. split the last element of #1 by end marker
# 3. choose the first element of #2
return text.split(begin)[-1].split(end)[0]
if __name__ == '__main__':
print('Example:')
print(between_markers('What is >apple<', '>', '<'))
# These "asserts" are used for self-checking and not for testing
assert between_markers('What is >apple<', '>', '<') == "apple"
assert between_markers('What is [apple]', '[', ']') == "apple"
assert between_markers('What is ><', '>', '<') == ""
assert between_markers('>apple<', '>', '<') == "apple"
print('Wow, you are doing pretty good. Time to check it!')
May 6, 2019
Comments: