Created
July 19, 2020 13:53
-
-
Save raeq/bef4514d8bb8d5b59b93af89550e454d to your computer and use it in GitHub Desktop.
Use REGEX to find text between two markers.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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