How to use a regular expression for email parsing

See also:
Capturing text with Regular Expressions
Online regex tester and debugger (regex101.com)
Exporting to Excel

Download this example

exporting email data to an excel file

This example shows how to use regular expressions (a very basic ones) to capture text from an incoming email. It also exports the resulting text to an excel file.

The email we receive is like the following:

From: test@example.com
To: example@example.com
Subject: Weather report
Temperature: 22.1
Pressure: 1032.6 hPa

Temperature: 22.3
Pressure: 1032.9 hPa

Temperature: 21.7
Pressure: 1033.1 hPa

Temperature: 20.8
Pressure: 1033.4 hPa

In order to capture the temperature and pressure values we configure the fields this way:

The regular expressions used are:

Temperature:\s+(?'temperature'.*)

Pressure:\s+(?'atmospheric_pressure'.*)
	

They are quite similar. Let’s separate the one that captures the temperature in two parts. Their meaning is as follows:

Regular expression part Meaning
Temperature:\s+ The word ‘Temperature’ followed by ‘:’ and then followed by one or multiple spaces
(?’temperature’.*) The field called ‘temperature’ is any string of consecutive characters.

Finally, when an email like this is received Email Parser produces this output and exports to Excel:


© 2008-2021 FrozenFrog Software  ·  Privacy Policy & Terms of Use
PAD file  ·  Old email parsing forums (now read only)