Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Comment solution in Clear category for Between Markers (simplified) by CedricVaruna
def between_markers(text: str, start: str, end: str) -> str:
"""
:param text: the input text to parse
:param start: the character marking the beginning of the substring
:param end: the character marking the end of the substring
:return: the substring enclosed between two markers
"""
# Preconditions
# The initial and final markers are always different.
assert start != end
# The initial and final markers are always 1 char size.
assert len(start) == 1 and len(end) == 1
# s.find(v, a, b) will search for v in s[a:b], returns -1 if not found
i = text.find(start) + 1
j = text.find(end, i)
# The initial and final markers always exist in a string and go one after another.
assert i != -1 and j != -1
return text[i:j]
Nov. 22, 2022
Comments: