Skip to content

Instantly share code, notes, and snippets.

@raeq
Created July 19, 2020 13:53
Show Gist options
  • Save raeq/bef4514d8bb8d5b59b93af89550e454d to your computer and use it in GitHub Desktop.
Save raeq/bef4514d8bb8d5b59b93af89550e454d to your computer and use it in GitHub Desktop.
Use REGEX to find text between two markers.
import re
def between(first: str = "", second: str = "", input_string="") -> str:
m = re.search(f"{first}(.+?){second}", input_string)
if m:
return m.group(1)
else:
return ""
assert between(input_string="adCCCTHETEXTZZZdfhewihu",
first="CCC",
second="ZZZ") == "THETEXT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment