I'm trying to find a way to detect and remove characters within a range of characters inside a string. Tried looping around and not much of a success and now experimenting for Regex.
So I'm supposed to input a filename e.g. [1080p]Godzilla.subs.mp4
or JohnnyEnglish_720[EnglishSubs].mp4
or [x264]psa_recording[1270x720].mp4
I'm supposed to remove all characters within the []
and output Godzilla.subs.mp4
or JohnnyEnglish_720.mp4 or
psa_recording.mp4`
import re
loop = True
list = []
while loop:
file_name = input("Filename?")
if file_name == '':
print(", ".join(list))
loop = False
else:
file_name = re.sub(r'[\[\[].*[\]\]]', '', file_name)
list.append(file_name)
It doesn't seems to be working for inputs that consists of more than 1 "[]"