String Manipulation on Email Body

I am trying to automate a process in which I am receiving an Outlook Email with some information…
I want to perform String Manipulation on it and then enter it into the specific website forms.
The info. I am receiving in email is in the following format


AIRCRAFT REG. N702A (H-900)
Origin Departure Destination
OEDF 0530Z OERK
OERK 1130Z OEDF

AIRCRAFT REG. N805XA (B-738)
Origin Departure Destination
OESB 0805Z OERK
OERK 1010Z OEJN
OEJN 1240Z OESB


Now I want to extract N702A(H-900) and then their Orign and departure details etc and then enter it into website form and then repeat the same phenomena for the other aircrafts with their multiple arrival/departure details

Thanks, in advance

@Sami_Rajput

system.text.regularExpression.regex.match(yourinputstring,“(?<=AIRCRAFT REG.\s).*”).value

gives you the required output

image

Thanks,
i also want to extract Orign, departure and destinations for the AirCrafts(There can be many Orign/Departure rows) for aircrafts and then repeat the same extraction phenomena for the other Aircrafts

Hi @Sami_Rajput

(?<=AIRCRAFT REG\.\s).*

Hope it helps!!

Hi @Sami_Rajput ,

I believe for this part, as it seems structured we should be able to use Generate Datatable from Text activity and get the data into a Datatable .

@pravallikapaluri @Shiva_Nikhil

Also want to extract Orign/Departure/ Destination

Appologies forgot to mention in the first writing

@Sami_Rajput

(?<=AIRCRAFT REG\.\s).*\s+.*

@Sami_Rajput

System.Text.RegularExpressions.Regex.Match(str,"(?<=AIRCRAFT REG\.\s).*\s+.*").Value.ReplaceLineEndings("")

You can use the following pattern to extract all values:

AIRCRAFT REG. (?<regnumber>.+)\r?\n.+\r?\n((?<origin>\S+)\s+(?<departure>\S+)\s+(?<destination>\S+)(\r?\n|$))+

It’s using named groups.

To get the reg number for the first match: matches(0).Groups("regnumber").Value
To get the origin value of the first match, on second row: matches(0).Groups("origin").Captures(1).Value

Example code:
ExtractTablesFromText.xaml (10.3 KB)

image

1 Like

hi @Sami_Rajput

Assign activity: emailContent = YourMailMessage.Body.ToString

Assign activity: aircraftDetails = System.Text.RegularExpressions.Regex.Match(emailContent, “AIRCRAFT REG. (.+?)\r\n”).Groups(1).Value

Assign activity: originDepartureDetails = System.Text.RegularExpressions.Regex.Matches(emailContent, “(\w{4}) (\d{4}Z) (\w{4})”).Cast(Of System.Text.RegularExpressions.Match)().Select(Function(match) match.Groups.Cast(Of Group)().Skip(1).Select(Function(group) group.Value).ToList()).ToList()

@Sami_Rajput

For aircraft reg use the regex and then use generate datatable activity with space spearation and get the remaining data into a datatable

Aircraft - "(?<=AIRCRAFT REG\.).*"

Then in generate datatable and pass the regex output as input string - "(?<=AIRCRAFT REG.*\n).*"

Cheersu