Split / Slice text content and retrieve only Select rows

Hi Makers,

This is a follow-up to this thread: Split text in single line into multiple parts

I receive text content from a mailhook → Split it into different lines → Use the data in certain lines to process the scenario further.

After implementing some excellent and detailed solutions presented by samliew, I was able to fix my issue of Splitting a line of text content into separate parts using RegEx. However, I encountered issues after running the scenario for the past week.

While I was certain that splitting the lines would ensure that certain content would ALWAYS be in certain rows of the array, I was proven wrong.

Are you very certain that the text you want to split will always be in the array index 4 and 5?

:arrow_up_small: this is the concern user @samliew raised from the get-go which did prove to be valid.

There are few instances where text being entered by users overruns the line limit for the line split and its placed into the next line. And that messes up the whole flow.

Here are input & output logs of a Set Variable module that’s splitting text received from mailhook by newline in a failing case:

input-module-failing-case.txt (1.7 KB)
output-module-failing-case.txt (1.6 KB)

first-text-content Array
1	Pure Chat
2	[https://app.purechat.com/content/images/logos/purechat-teal-small.png]
3	https://app.purechat.com Missed Chat
4	Your Name: Tester Date: 1/7/2024 Your Email: Tester1@yahoo.co.in Your
5	Number: 1234567890 Your Requirement: Extra detailed requirement mentioned
6	comes here Website:
7	https://www.domain.com/page-post-name/
8	[https://www.domain.com/page-post-name/]
9	Source: https://www.google.com/ [https://www.google.com/] Operator: - Tags: -
10	Tester 17:11
11	joined the chat
12	Tester 17:11
13	Extra detailed requirement mentioned comes here
14	This chat was closed because the visitor left the page or lost internet
15	connectivity.
16	Thanks for using Pure Chat!
17	Details:
18	Date: 1/7/2024
19	Operator: No operator
20	Website: https://www.domain.com/page-post-name/
21	Source: https://www.google.com/
22	IP Address: 192.168.1.1
23	Rating: No Rating
24	Feedback:
25	Your Number: 1234567890
26	Your Requirement: Extra detailed requirement mentioned comes here
27	Your Email: Tester1@yahoo.co.in
28	Tags:
29	[1/7/2024 - 17:11] Tester joined the chat
30	[1/7/2024 - 17:11] Tester said:
31	Extra detailed requirement mentioned comes here

For comparison, Here are the input and output modules from the previous case we first looked at in the linked thread above and found the original solution for:

line_split_module_input.txt (1.4 KB)
line_split_module_output.txt (1.3 KB)

Sometimes the Your Requirement text is long and overruns into the next line and that’s causing the scenario to not run as expected.

Theory: If I can remove all the lines in the array from 1 to 17 and then work with the content after line 17 in any instance, that would solve the issue probably.

Any advice on how I can tackle this?

What happens if you don’t split the lines in the first place?

Could you please provide the output bundle of a previous module that doesn’t have it split in different lines yet?

Hi @samliew ,

Here is the output bundle of the mailhook (Module.1), that’s the starting point of the scenario.

Module.1 - mailhook-output-module.txt (19.8 KB)

I’m also including the input bundle of the next module, which takes the text-content from the array before splitting it into different lines.

Module.2 - input-module-line-split.txt (2.0 KB)

Welcome to the Make community!

You do NOT need these modules:

You can use a Text Parser “Match Pattern” module with this Pattern (regular expression):

Your Name:\s+(?<name>.+)\s+Date:\s+(?<date>.+)\s+Your Email:\s+(?<email>.+)\s+Your Number:\s+(?<number>.+)\s+Your Requirement:\s+(?<requirement>.+)\s+Website:

Proof

https://regex101.com/r/2uQZDQ/1

Important Info

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

Screenshot

Output


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!

samliewrequest private consultation

Join the Make Fans Discord server to chat with other makers!

Module Export

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

  1. Copy the JSON 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 (paste keyboard shortcut for Windows) to paste directly in the canvas.

  3. Click on each imported module and save it for validation. You may be prompted to remap some variables and connections.

Click to Expand Module Export Code

JSON - Copy and Paste this directly in the scenario editor

{
    "subflows": [
        {
            "flow": [
                {
                    "id": 1,
                    "module": "regexp:Parser",
                    "version": 1,
                    "parameters": {
                        "pattern": "Your Name:\\s+(?<name>.+)\\s+Date:\\s+(?<date>.+)\\s+Your Email:\\s+(?<email>.+)\\s+Your Number:\\s+(?<number>.+)\\s+Your Requirement:\\s+(?<requirement>.+)\\s+Website:",
                        "global": false,
                        "sensitive": true,
                        "multiline": false,
                        "singleline": false,
                        "continueWhenNoRes": false
                    },
                    "mapper": {
                        "text": "{{88.text}}"
                    },
                    "metadata": {
                        "designer": {
                            "x": 265,
                            "y": -1700
                        },
                        "restore": {
                            "parameters": {
                                "sensitive": {
                                    "collapsed": true
                                },
                                "multiline": {
                                    "collapsed": true
                                },
                                "singleline": {
                                    "collapsed": true
                                },
                                "continueWhenNoRes": {
                                    "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
                            }
                        ],
                        "expect": [
                            {
                                "name": "text",
                                "type": "text",
                                "label": "Text"
                            }
                        ],
                        "interface": [
                            {
                                "type": "text",
                                "name": "name",
                                "label": "name"
                            },
                            {
                                "type": "text",
                                "name": "date",
                                "label": "date"
                            },
                            {
                                "type": "text",
                                "name": "email",
                                "label": "email"
                            },
                            {
                                "type": "text",
                                "name": "number",
                                "label": "number"
                            },
                            {
                                "type": "text",
                                "name": "requirement",
                                "label": "requirement"
                            }
                        ]
                    }
                }
            ]
        }
    ],
    "metadata": {
        "version": 1
    }
}

That worked like a charm! I tweaked the regex a bit and was able to make it just right.

I decided to take things further and retrieve the contents of the Chat conversation as well. Modifying the Regex for the chat conversation contents works for cases where:

Case A. The customer actually engages in the chat and types ANYTHING.

Output bundle for Case A:

Module.1 - mailhook-output-module.txt (19.8 KB)

Text content from the Mailhook for Case A :–

Pure Chat
[https://app.purechat.com/content/images/logos/purechat-teal-small.png]
https://app.purechat.com Missed Chat

Your Name: Tester_name Date: 2/7/2024 Your Email: tester_email@email.com Your Number:
1234567890 Your Requirement: Specifications of project mentioned Website:
https://www.domain.com/page-post-title-here/
[https://www.domain.com/page-post-title-here/] Source:
https://www.google.com/ [https://www.google.com/] Operator: - Tags: -

Tester_name 18:06
joined the chat
Tester_name 18:06
Specifications of the project as mentioned
Building specifications
What are the building specifications of the project
Tester_name 18:10
I need response
This chat was closed by the visitor.

Thanks for using Pure Chat!
Details:
     Date: 2/7/2024
     Operator: No operator
     Website: https://www.domain.com/page-post-title-here/
     Source: https://www.google.com/
     IP Address: 192.168.1.1
     Rating: No Rating
     Feedback: 
     Your Number: 1234567890
     Your Requirement: Specifications of project mentioned
     Your Email: tester_email@email.com
     Tags: 


[2/7/2024 - 18:06] Tester_name joined the chat

[2/7/2024 - 18:06] Tester_name said:
Specifications of the project mentioned 

[2/7/2024 - 18:08] Tester_name said:
Building specifications 

[2/7/2024 - 18:09] Tester_name said:
What are the building specifications of the project 

[2/7/2024 - 18:10] Tester_name said:
I need response 


However, there are some cases where:

Case B. They just activate the chat, wait a minute or more, and then just close it. No interactions.

Output bundle for Case B:

Case B - mailhook-output-module no response.txt (16.7 KB)

Text Content from the Mailhook for Case B :-

Pure Chat
[https://app.purechat.com/content/images/logos/purechat-teal-small.png]
https://app.purechat.com Missed Chat

Your Name: Testing Date: 9/7/2024 Your Email: testing@domian.com Your Number:
1234567890 Your Requirement: Test requirements here Website:
https://www.domain.com/page-post-name/
[https://www.domain.com/page-post-name/]
Source: https://www.google.com/ [https://www.google.com/] Operator: - Tags: -

Testing 11:38
joined the chat
This chat was closed by the visitor.

Thanks for using Pure Chat!
Details:
     Date: 9/7/2024
     Operator: No operator
     Website: https://www.domain.com/page-post-name/
     Source: https://www.google.com/
     IP Address: 192.168.1.1
     Rating: No Rating
     Feedback: 
     Your Number: 1234567890
     Your Requirement: Test requirements here
     Your Email: testing@domian.com
     Tags: 


[9/7/2024 - 11:38] Testing joined the chat

I tried my hand at this simple Regex to grab all the chat conversation content:

https://regex101.com/r/2uQZDQ/2

This Regex can grab chat content if it’s Case A. However if its Case B, it won’t work.

How can I get it to work in either case?