From 1cf220991013e31139ea91f3eda0936392b902fc Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Thu, 26 Nov 2020 18:18:47 -0800 Subject: [PATCH] Add function excise. --- voussoirkit/stringtools.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/voussoirkit/stringtools.py b/voussoirkit/stringtools.py index 88ca349..4704303 100644 --- a/voussoirkit/stringtools.py +++ b/voussoirkit/stringtools.py @@ -19,6 +19,18 @@ def comma_space_split(text): return text return re.split(r'[ ,]+', text.strip()) +def excise(text, mark_left, mark_right): + ''' + Remove the text between the left and right landmarks, including the + landmarks themselves, and return the rest of the text. + + excise('What a wonderful day [soundtrack].mp3', ' [', ']') -> + returns 'What a wonderful day.mp3' + ''' + if mark_left in text and mark_right in text: + return text.split(mark_left, 1)[0] + text.rsplit(mark_right, 1)[-1] + return text + def pascal_to_loudsnakes(text): ''' PascalCase -> PASCAL_CASE