Between Markers (simplified)

Between Markers (simplified)

You are given a string and two markers (the initial one and final). You have to find a substring enclosed between these two markers. But there are a few important conditions.

  • The initial and final markers are always different.
  • The initial and final markers are always 1 char size.
  • The initial and final markers always exist in a string and go one after another.

example

Input: Three arguments. All of them are strings (str). The second and third arguments are the initial and final markers.

Output: A string (str).

Examples:

assert between_markers("What is >apple<", ">", "<") == "apple"
assert between_markers("What is [apple]", "[", "]") == "apple"
assert between_markers("What is ><", ">", "<") == ""
assert between_markers("[an apple]", "[", "]") == "an apple"

How it is used: For text parsing.

Precondition: There can't be more than one final and one initial markers.

40