import re with open('_get_instance_details.php', 'r') as f: content = f.read() pattern = re.compile(r"<\?php foreach \(\$currentNode\[\'ui_hints\'\]\[\'form_schema\'\] as \$field\): \?>(.*?)<\?php endforeach; \?>", re.DOTALL) replacement = r"""<\?php foreach ($currentNode['ui_hints']['form_schema'] as $field): $fieldName = $field['name']; $currentValue = $instanceData[$fieldName] ?? null; ?>
>
" if pattern.search(content): content = pattern.sub(lambda m: replacement, content, count=1) with open('_get_instance_details.php', 'w') as f: f.write(content) print("Patched successfully!") else: print("Pattern not found!")