import re # Regular expression to extract the master ticket number pattern = re.compile(r'<master_ticket_number>(\d+)</master_ticket_number>') # File path file_path = 'file.xml' # Open the file and read each line with open(file_path, 'r') as file: for line in file: # Search for the pattern in the line match = pattern.search(line) if match: # Extract and print the ticket number ticket_number = match.group(1) print("Master Ticket Number:", ticket_number)