Add function excise.

This commit is contained in:
voussoir 2020-11-26 18:18:47 -08:00
parent 2cb443cf6d
commit 1cf2209910

View file

@ -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