Splitting sections in an imported text file

The x should say d in this line:

c = re.sub('\[^\]','',x)

Apart from that, this code should run without errors.

Could you try it again? If it still gives an error, could you please post the full error message, with the traceback included.

I ran it and there weren’t any errors however, from the image, you can see that the [ ] still exist, it does not seem like the code has removed them?
For example here:
CHIRON:Tell us, old man, how shall we be employ’d?
TITUS ANDRONICUS:Tut, I have work enough for you to do. Publius, come hither, Caius, and Valentine!
[Enter PUBLIUS and others]

PUBLIUS:What is your will?
TITUS ANDRONICUS:Know you these two?
PUBLIUS:The empress’ sons, I take them, Chiron and Demetrius.
TITUS ANDRONICUS:Fie, Publius, fie! thou art too much deceived; The one is Murder, Rape is the other’s name; And therefore bind them, gentle Publius. Caius and Valentine, lay hands on them. Oft have you heard me wish for such an hour, And now I find it; therefore bind them sure, And stop their mouths, if they begin to cry.
[Exit]

[PUBLIUS, &c. lay hold on CHIRON and DEMETRIUS]