Gmail => google sheets (text parser)

Hello,

I have a problem and I don’t know what solution is best to use.
I receive an email with the following syntax:

Invoice no.: 6089856/13/2024/F
Amount to be paid:
$424.45
payment date
13/02/2024

Invoice no.: 7089856/13/2024/F
Amount to be paid:
$324.45
payment date
14/02/2024

Invoice no.: 8089856/13/2024/F
Amount to be paid:
USD 224.45
payment date
15/02/2024

I want the above information to be transferred to Google Sheets as follows:
column A - 6089856/13/2024/F
column B - USD 424.45
column C - 13/02/2024

What’s the best way to approach the topic? Use text parser (match pattern) or is there another way?

Welcome to the Make community!

You can use a Text Parser “Match Pattern” module with this regular expression pattern

Invoice no\.:\s+(?<invoice>[^\n]+)\s+Amount to be paid:\s+(?:\$|USD\s)(?<amount>\d[\d,]+(?:\.\d{2})?)\s+payment date\s+(?<date>\d{2}\/\d{2}\/\d{4})

Regex test: https://regex101.com/r/b7Ybg9

Important Info

  • :warning: Global match must be set to YES!

Screenshot

Output

Screenshot_2024-02-02_190221


For more information, see Text Parser in the Make Help Center:

Match Pattern
The Match pattern module enables you to find and extract string elements matching a search pattern from a given text. The search pattern is a regular expression (aka regex or regexp), which is a sequence of characters in which each character is either a metacharacter, having a special meaning, or a regular character that has a literal meaning.

Hope this helps!

3 Likes

Then, you can map each of the matched values in the columns in Google Sheets.

Screenshot_2024-02-02_190253

You can copy and paste this module export into your scenario. This will paste the modules shown in my screenshots above.

  1. Copy the code below by clicking the copy button when you mouseover the top-right of the code block
    Screenshot_2024-01-17_200117

  2. Enter your scenario editor. Press ESC to close any dialogs. Press CTRLV to paste in the canvas.

  3. Click on each imported module and save it. You may need to remap some variables.

Modules JSON Export

{
    "subflows": [
        {
            "flow": [
                {
                    "id": 34,
                    "module": "util:ComposeTransformer",
                    "version": 1,
                    "parameters": {},
                    "mapper": {
                        "value": "Invoice no.: 6089856/13/2024/F\nAmount to be paid:\n$424.45\npayment date\n13/02/2024\n\nInvoice no.: 7089856/13/2024/F\nAmount to be paid:\n$324.45\npayment date\n14/02/2024\n\nInvoice no.: 8089856/13/2024/F\nAmount to be paid:\nUSD 224.45\npayment date\n15/02/2024"
                    },
                    "metadata": {
                        "designer": {
                            "x": -294,
                            "y": -704
                        },
                        "restore": {},
                        "expect": [
                            {
                                "name": "value",
                                "type": "text",
                                "label": "Text"
                            }
                        ]
                    }
                },
                {
                    "id": 35,
                    "module": "regexp:Parser",
                    "version": 1,
                    "parameters": {
                        "pattern": "Invoice no\\.:\\s+(?<invoice>[^\\n]+)\\s+Amount to be paid:\\s+(?:\\$|USD\\s)(?<amount>\\d[\\d,]+(?:\\.\\d{2})?)\\s+payment date\\s+(?<date>\\d{2}\\/\\d{2}\\/\\d{4})",
                        "global": true,
                        "sensitive": true,
                        "multiline": false,
                        "singleline": false,
                        "continueWhenNoRes": false,
                        "ignoreInfiniteLoopsWhenGlobal": false
                    },
                    "mapper": {
                        "text": "{{34.value}}"
                    },
                    "metadata": {
                        "designer": {
                            "x": -48,
                            "y": -702
                        },
                        "restore": {
                            "parameters": {
                                "multiline": {
                                    "collapsed": true
                                },
                                "singleline": {
                                    "collapsed": true
                                }
                            }
                        },
                        "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
                            },
                            {
                                "name": "ignoreInfiniteLoopsWhenGlobal",
                                "type": "boolean",
                                "label": "Ignore errors when there is an infinite search loop",
                                "required": true
                            }
                        ],
                        "expect": [
                            {
                                "name": "text",
                                "type": "text",
                                "label": "Text"
                            }
                        ],
                        "interface": [
                            {
                                "type": "text",
                                "name": "invoice",
                                "label": "invoice"
                            },
                            {
                                "type": "text",
                                "name": "amount",
                                "label": "amount"
                            },
                            {
                                "type": "text",
                                "name": "date",
                                "label": "date"
                            },
                            {
                                "type": "uinteger",
                                "name": "i",
                                "label": "i"
                            },
                            {
                                "type": "any",
                                "name": "__IMTMATCH__",
                                "label": "Fallback Match"
                            }
                        ]
                    }
                },
                {
                    "id": 37,
                    "module": "google-sheets:addRow",
                    "version": 2,
                    "metadata": {
                        "designer": {
                            "x": 196,
                            "y": -702
                        }
                    }
                }
            ]
        }
    ],
    "metadata": {
        "version": 1
    }
}
4 Likes

Thank you, it works perfectly!

1 Like