I have extracted an email from my mailbox. In this email there is structured data (name, adress, postal code, etc.). I want to extract this data from the email, but I can’t figure out how to do it. Example of the email:
Hi,
Some random text.
Name: great name
Adres: streetname 123
City: best city
Postal code: 1234 XG
Kind regards,
a person.
I want to save the name in a variable str_name, adres in str_adress, city in str_city, etc. Can someone explain to me how to do this? Do note, the name can exist out of 2, 3, 4 or more words, same of the city and adres. Length of these values is unknown up front.
You can get the whole message string and split it by newline character so you get the array of each line as string… Now check either : exist or not - if yes split it using : and put the result in dictionary… Now you can access each detail using dictionary.
Note: if complete name/dress found in same line means use this, else better to use regEx. (To use regEx the input format should be same as this everytime. I.e address comes after name always or postal comes after City always )