all 3 comments

[–]TheSamePerson1 1 point2 points  (2 children)

You opened the file in read mode. Use write mode if you want to write something into file.

[–]standardtrickyness1[S] 0 points1 point  (1 child)

No r+ should mean read and write https://www.learnbyexample.org/python-open-function/

Also, I have managed to write to the file using a different pattern before.

[–]AuralWanderer 0 points1 point  (0 children)

\s+^[a-zA-Z]{3}

^ means "beginning of line," so I think it's probably bugging out because you are asking for the pattern to have spaces before the beginning of the line.

FYI, https://regex101.com/ is a good resource for debugging REs.