I want to remove some characters from a string which are inside square brackets, regardless of the type of character as well as the amount of characters inside the square brackets. However, the type of brackets and their order does not change. Lastly, I want to remove the square brackets as well.
For example:
my_string1 = 'this[123]'
my_string2 = 'is[7]'
my_string3 = 'my[i]'
my_string4 = 'example[jk]'
Desired output:
my_string1 = 'this'
my_string2 = 'is'
my_string3 = 'my'
my_string4 = 'example'
Using re.sub() does not work for me:
import re
my_string1 = 'this[112]'
print(re.sub("[[]|[]]", "", my_string1))
The best output I got:
'this112'