import re with open('addons/education_lms/security/security.xml', 'r') as f: text = f.read() text = re.sub( r'.*?', """ Student Course Access [(1, '=', 1)] """, text, flags=re.DOTALL ) with open('addons/education_lms/security/security.xml', 'w') as f: f.write(text)