Reputation: 15
I just started python and I have a quick question about strings. Say I have a string that contains both an open and closed bracket (with characters in it) that looks something like this:
result = 10['1', '0']0
What I would like to know is how I can manipulate the string to make it look like this:
result = 100
Upvotes: 0
Views: 49
Reputation: 174696
Seems like you're trying to replace characters present inside the square brackets (including brackets) with an empty string .
In [8]: result = "10['1', '0']0"
In [9]: re.sub(r'\[[^\]]*\]', '', result)
Out[9]: '100'
Upvotes: 1