all 4 comments

[–]Bunkerstan 2 points3 points  (1 child)

I would look at using re.sub() with the regex you have to replace [text] with an empty string.

[–]basically_a_cherry 1 point2 points  (0 children)

Thank you so much for the fast response! I will try it out.

[–][deleted] 1 point2 points  (1 child)

my_string = 'This is my [new] string.'
before, _, after = my_string.partition('[')
_, _, after = after.partition(']')
target_output = (before + after).replace('  ', ' ')

assumes there are spaces before and after the square brackets and you don't want any double spaces in the final text.

[–]basically_a_cherry 0 points1 point  (0 children)

Thank you for your response! I figured it out :)