import re file_path = 'src/main/resources/static/js/manage/editor-plugins/training-course.js' with open(file_path, 'r') as f: content = f.read() # I will just write a new file instead of regex replacing it because it's safer.