Jun-24-2018, 09:18 AM
(Jun-24-2018, 08:24 AM)kerzol81 Wrote: Hi,
Could you help me out a bit? I'd like to remove those colored characters out of a bunch of files like these:
a = 'Python Tutorial for Beginners 1 - Install and Setup for Mac and Windows-YYXdXT2l-Gg.mkv'
b = 'Python Tutorial for Beginners 2 - Strings - Working with Textual Data-k9TUPpGqYTo.mkv'
I'm here so far:
def replacer(filename): n = re.findall('-[^a-zA-Z0-9]', filename) print(n)The regex would be like this
always starts with a - character, followed by a letter, until a . which is the file extension.
Thanks
That will do the trick
re.sub(r'-\w+(?=\.))', '', 'Windows-YYXdXT2l-Gg.mkv')but if you what to use RegEx - you better learn them. This site is the excellent playing ground to learn RE.
Test everything in a Python shell (iPython, Azure Notebook, etc.)
- Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
- Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
- You posted a claim that something you did not test works? Be prepared to eat your hat.