Source Code:
(back to article)
marker1 = "start" marker2 = "end" # The string you want to extract the substring from string = "This is the start of the substring and this is the end" # Find the index of the first marker start = string.find(marker1) # Find the index of the second marker end = string.rfind(marker2) # Use slicing to extract the substring between the markers substring = string[start+len(marker1):end] print(substring) # Output: " of the substring and this is the "
Result:
Report an issue