Email Body Content and Structured Data Extractor - n8n Workflow

Master data extraction using a custom n8n node. This n8n workflow template uses RegEx in a Function node to parse unstructured email bodies into clean JSON objects, ideal for automation.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Automation specialists needing to extract structured data from inconsistent text formats.
n8n developers looking for advanced RegEx and Function n8n node examples.
Users building robust intake systems that process emails or text files where key-value pairs are separated by newlines.
Anyone needing highly reliable n8n templates for data preprocessing.

Overview

This powerful n8n workflow addresses the common challenge of dealing with unstructured text data, such as standard inquiry emails or form submissions, where keys and values are listed but not cleanly separated. By leveraging the flexibility of the n8n Function node and targeted Regular Expressions, this n8n template automatically identifies and extracts specific fields (like Name, Email, Subject) based on a defined list of labels.

This process transforms messy text into standardized, usable JSON outputs, making subsequent steps in your n8n workflow — such as updating a CRM or Google Sheet — reliable and straightforward. This sophisticated n8n node configuration is a must-have tool for data cleanup, providing a repeatable structure for complex text extraction within any large-scale n8n automation.

How it Works


  1. Initiation: The n8n workflow is started using the On clicking 'execute' n8n trigger. In a production environment, you would swap this for a real n8n trigger (like a Gmail n8n node or Webhook n8n node) that provides the email body text.

  2. Data Simulation: The Set values n8n node simulates an incoming dataset. It defines the raw text to be parsed (body) and provides a comma-separated list of the fields (or labels) the script must look for (Name,Email,Subject,Message).

  3. Core Parsing Logic: The data is passed to the Email Parser Snippet n8n node (a Function node). This n8n node contains the custom JavaScript logic and RegEx.

  4. RegEx Extraction: The script iterates through the provided labels. For each label, it constructs a RegEx pattern to find the label, followed by a colon or space, and then captures the subsequent value. The logic is specifically designed to handle the last label in the list differently, allowing it to capture multi-line text (like a full message body) until the end of the input, making this n8n workflow highly versatile.

  5. Output: The n8n node returns a clean JSON object, structuring the data previously trapped in the raw text.

Installation Guide


  1. Download the n8n workflow JSON: Save the provided JSON code block.

  2. Import into n8n: Open your n8n instance, navigate to 'Workflows', and use the 'Import from JSON' option.

  3. Review the Function n8n node: Examine the Email Parser Snippet n8n node to understand how the RegEx handles different fields. Modify the Set values n8n node to test the extraction with your specific text format.

  4. Replace the Trigger: Replace the starting On clicking 'execute' n8n trigger with your desired input n8n trigger (e.g., Gmail, IMAP, or a Webhook) to run the n8n workflow live. Ensure the input data from the real n8n trigger sets the body and labels variables correctly for the Function n8n node.

Node Details

On clicking 'execute' (n8n trigger):
Function: Acts as a manual start n8n trigger for testing and development of the n8n workflow.
Key Configuration: Standard manual n8n trigger setup.
Set values (n8n node):
Function: This essential n8n node provides the initial test data. It defines the unstructured input text in the body field and explicitly defines the list of required fields to search for in the labels field.
Key Configuration: body contains the raw simulated email input; labels contains the comma-separated keys ("Name,Email,Subject,Message").
Email Parser Snippet (Function n8n node):
Function: The core processing n8n node. It contains custom JavaScript that iterates through the defined labels and uses sophisticated RegEx patterns to match and extract data from the input body. This n8n node intelligently determines where each field's value ends, ensuring clean extraction, even for multi-line messages.
Key Configuration*: Custom JavaScript logic for RegEx parsing.

Related n8n Workflows

Free

Nodes: 3 Nodes
Updated: December 26 2025
View all
Created by
Miquel Colomer
Miquel Colomer

Featured*