Extracting string from ann email body
07:12 02 Dec 2024

I'm using python to extract the information provided from the body of an email using imap.

Part of the email that interests to my code: "BOT ID: 4824CF8B-2986-11EC-80F0-84A93851B964"

I can extract the exact string from the email body with

    if content_type == "text/plain" and "attachment" not in content_disposition:
        import re
        ID_pattern = r"BOT ID: (\w+)-(\w+)-(\w+)-(\w+)-(\w+)"
        machine_id = re.findall(ID_pattern, body)
        print(machine_id)

But it returns: "[('4824CF8B', '2986', '11EC', '80F0', '84A93851B964')]"

How can I manipulate this turple/list to keep que original pattern: xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx

Thank u all guys.

import re
ID_pattern = r"BOT ID: (\w+)-(\w+)-(\w+)-(\w+)-(\w+)"
machine_id = re.findall(ID_pattern, body)
print(machine_id)

result: [('4824CF8B', '2986', '11EC', '80F0', '84A93851B964')]

Expected: 4824CF8B-2986-11EC-80F0-84A93851B964

python string list python-re