I am required to remove the elements within the square bracket of the string. However, I am unable to get my desired results.
Below is desired the output I am required to get:
Example of the Output
[[apple].png -> [.png
[apple]].png -> ].png
[[apple]].png -> [].png
[an]apple[adaykeeps]]the[[doctor]away.png -> apple]the[away.png
The methods I've used are mentioned below, but I am not able to get my required output:
Regex Method
file = re.sub(r'(\d*\D+\d*)\s+','',re.sub(r'{.+?#(\d+).\d+)}',r'(\1)',file));
SubString Method
openbracket = file.find('['); closebracket = file.find(']');
if len(file) > closebracket : file = file[0: openbracket:] + file[closebracket + 1::]