import re path = r'c:\Users\Admin\Metatron_Student_ERP\addons\education_portal\views\portal_templates.xml' with open(path, 'r', encoding='utf-8') as f: content = f.read() # Replace mr-X with mr-X me-X def replace_class(m): cls = m.group(1) num = m.group(2) if f'me-{num}' not in cls: cls = cls + f' me-{num}' return f'class="{cls}"' new_content = re.sub(r'class="([^"]*?\bmr-(\d)\b[^"]*?)"', replace_class, content) # Add space after /> if there is text directly new_content = re.sub(r'(]*?/>)([A-Za-z0-9])', r'\1 \2', new_content) # Add space after if there is text directly new_content = re.sub(r'()([A-Za-z0-9])', r'\1 \2', new_content) if new_content != content: with open(path, 'w', encoding='utf-8') as f: f.write(new_content) print('Updated portal_templates.xml') else: print('No changes needed in portal_templates.xml')