import re case_pattern = re.compile(r"case\s(?P[^:]*):\s*.*?new GUIContent\((?P\"[^\"]*\")\);") with open("input.txt", "r", encoding="utf-8") as f: with open("result.txt", "w", encoding="utf-8") as fo: for m in case_pattern.finditer(f.read()): fo.write(f"[{m.group('name')}] = {m.group('val')},\n")