Text parser: multiple named groups in single bundle

Using the text parser module is there a way to take the following string and output multiple groups (for the text after the colon on each line) in a single bundle?

Job Number: 82722
Contact First Name: John
Contact Last Name: Smith
Contact Email: j.smith1000@gmail.com
Contact Mobile: 0400 000 000
Contact Address1: 100 Fake Beach Drive
Location Address2: 
Location Suburb: Fakeburbs
Location State: QLD
Location Postcode: 4000

Hi Ryan,

This should get you started. Regex101 is usually where most of us craft our Regex patterns.
Note the highlighted thing on the left.

You’ll use the Text Parser (match pattern) module in Make

2 Likes

Ok yeah that works! Thanks, saves me a lot of hassle not having to aggregate and mess around with no labels!

Do you know of a way to do the same thing but not have to be an exact match on the full string? For example, if one was missing or it was in a different order?

1 Like

Highly recommend you read up on Regular Expressions first.

When you say “exact match” on the full string you’ll need to define some sort of pattern you want to match that is not exact and then encode that into the regular expression. The missing and different order all use modifiers like ? or look ahead/behind modifiers and make for a more complex string. If you need help share what you have and one of the regex geeks will jump in.

2 Likes

ahaaaaa thanks for that Alex - brilliant resource (and of course (@Bjorn.drivn for the small task of writing the article!!!)

2 Likes

Hi @ryan.a , you can use this regular expression that, regardless of the order, whether it has or not a value, will still return data.

/^Job Number: (?<jobNumber>\d*)|^Contact First Name: (?<firstName>.*)|^Contact Last Name: (?<lastName>.*)|^Contact Email: (?<email>.*)|^Contact Mobile: (?<mobile>.*)|^Contact Address1: (?<address1>.*)|^Contact Address2: (?<address2>.*)|^Location Suburb: (?<locationSuburb>.*)|^Location State: (?<locationState>.*)|^Location Postcode: (?<locationPoscode>.*)/gm

1 Like

@ryan.a, In case that some answer to your question, could you please :white_check_mark: mark the reply as a solution?

It helps keep the community space tidy :blush:

Thanks a lot!

1 Like

Thanks, this is what I’m looking for but…

(a) I can’t get your regex to run in Make

(b) Using pipes (|) causes it to output multiple bundles, not a single bundle

Thanks, Alex. I’m familiar with regex but not an expert.

To add some clarity to what I’m trying to achieve:

  1. Using an OR operator, I’m able to get it to do what I want – match each item, regardless of order or if it exists – however, it outputs each match as a separate bundle which means I then need to aggregate it

  2. Using the following regex, I can get a single bundle but only if every item is present and in that exact order

Job Number: \s*(?.)\nContact First Name:\s(?.)\nContact Last Name:\s(?.)\nContact Email:\s(?.)\nContact Mobile:\s(?.)\nContact Address1:\s(?.)\nLocation Address2:\s(?.)\nLocation Suburb:\s(?.)\nLocation State:\s(?.)\nLocation Postcode:\s(?.*)

Looking for a solution that allows the flexibility of (1) but only outputs a single bundle as per (2)

Any thoughts on this @Francisco_Fontes?

Why don’t you just use an array aggregator module after the text parser to combine all the output bundles into one array that way you can deal with them as one array in subsequent modules rather than separate bundles?

1 Like

I spent a heap of time playing with the array aggregator and the other various aggregators but what happens is the array aggregator spits out something like this:

{
    {
        name: jon
        phone: null
        address: null
    },
    {
        name: null
        phone: 0400 000 000
        address: null
    },
    {
        name: null
        phone: null
        address: 12 Fake St
    }
}

I couldn’t find a way to then map a field if it wasn’t blank.