How to parse a multiline text with name value pairs

Hi everone,

I receive emails with texts similar to this:

Last Name = Teichmann
First Name = Martin
Company = Erneuerbare Energien Teichmann GbR
Street = Burgstraße 28 a
ZIP = 34637
City = Schrecksbach
FullCity = 34637 Schrecksbach
Country = Germany
State / Province =
Phone = +49 17682135917

I would like to parse the text and insert the fields as a new row in a Google Sheet.

I am unsure how to handle this. Should I split the text into single lines and then split each line into the name: value pairs?

Or should I use a regex for each field?

Thanks
Vaclav

Hey @Vaclav_Jedlicka
Welcome to the make community

You can use the regex

Last Name\s*=\s*(.*?)\s*First Name\s*=\s*(.*?)\s*Company\s*=\s*(.*?)\s*Street\s*=\s*(.*?)\s*ZIP\s*=\s*(.*?)\s*City\s*=\s*(.*?)\s*FullCity\s*=\s*(.*?)\s*Country\s*=\s*(.*?)\s*State \/ Province\s*=\s*(.*?)\s*Phone\s*=\s*(.*)

Module

{
“subflows”: [
{
“flow”: [
{
“id”: 2,
“module”: “regexp:Parser”,
“version”: 1,
“parameters”: {
“pattern”: “Last Name\s*=\s*(.?)\sFirst Name\s*=\s*(.?)\sCompany\s*=\s*(.?)\sStreet\s*=\s*(.?)\sZIP\s*=\s*(.?)\sCity\s*=\s*(.?)\sFullCity\s*=\s*(.?)\sCountry\s*=\s*(.?)\sState \/ Province\s*=\s*(.?)\sPhone\s*=\s*(.*)”,
“global”: false,
“sensitive”: true,
“multiline”: false,
“singleline”: false,
“continueWhenNoRes”: false
},
“mapper”: {
“text”: “Last Name = Teichmann\nFirst Name = Martin\nCompany = Erneuerbare Energien Teichmann GbR\nStreet = Burgstraße 28 a\nZIP = 34637\nCity = Schrecksbach\nFullCity = 34637 Schrecksbach\nCountry = Germany\nState / Province =\nPhone = +49 17682135917”
},
“metadata”: {
“designer”: {
“x”: 253,
“y”: 81,
“messages”: [
{
“category”: “last”,
“severity”: “warning”,
“message”: “A transformer should not be the last module in the route.”
}
]
},
“restore”: {},
“parameters”: [
{
“name”: “pattern”,
“type”: “text”,
“label”: “Pattern”,
“required”: true
},
{
“name”: “global”,
“type”: “boolean”,
“label”: “Global match”,
“required”: true
},
{
“name”: “sensitive”,
“type”: “boolean”,
“label”: “Case sensitive”,
“required”: true
},
{
“name”: “multiline”,
“type”: “boolean”,
“label”: “Multiline”,
“required”: true
},
{
“name”: “singleline”,
“type”: “boolean”,
“label”: “Singleline”,
“required”: true
},
{
“name”: “continueWhenNoRes”,
“type”: “boolean”,
“label”: “Continue the execution of the route even if the module finds no matches”,
“required”: true
}
],
“expect”: [
{
“name”: “text”,
“type”: “text”,
“label”: “Text”
}
],
“interface”: [
{
“type”: “text”,
“name”: “$1”,
“label”: “$1”
},
{
“type”: “text”,
“name”: “$2”,
“label”: “$2”
},
{
“type”: “text”,
“name”: “$3”,
“label”: “$3”
},
{
“type”: “text”,
“name”: “$4”,
“label”: “$4”
},
{
“type”: “text”,
“name”: “$5”,
“label”: “$5”
},
{
“type”: “text”,
“name”: “$6”,
“label”: “$6”
},
{
“type”: “text”,
“name”: “$7”,
“label”: “$7”
},
{
“type”: “text”,
“name”: “$8”,
“label”: “$8”
},
{
“type”: “text”,
“name”: “$9”,
“label”: “$9”
},
{
“type”: “text”,
“name”: “$10”,
“label”: “$10”
}
]
}
}
]
}
],
“metadata”: {
“version”: 1
}
}

You can map the output in google sheet

1 Like

Hi Growwstacks,
thank you very much for your help!

Unfortunately I have no idea what to do with the texts you provided.
I added a Text parser, entered the regex in the first field.

Then I right-clicked the module and selected “Run this module only”.
Then a dialog labeled “Mappings” appears. What do I do next?

Thanks
Vaclav