Best answer

How to find a certain string of text/pattern?

  • 8 November 2023
  • 23 replies
  • 563 views

Userlevel 1
Badge +1

So as the title suggests, I’m trying to find a certain pattern/string of text in a text field.

 

In the selected field, I want to extract every instance of EMB 1. I’m at a loss of how I would do that though.

icon

Best answer by DarkRoom 10 November 2023, 14:29

View original

This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

23 replies

Userlevel 7
Badge +14

Hi @DarkRoom 

Good question.

Can you further describe the desired output using a specific example.

Perhaps try this Zap action: Formatter > Text > Extract Pattern

Userlevel 1
Badge +1

To be more specific, I want to extract every mention of specific words/phrases. In this case it would be EMB 1. I want to use every mention of the specified word (EMB 1 is mentioned 3 times here) individually to make 3 separate items in Monday.com containing the word I’m referencing.

 

As far as using the action you had mentioned, I’m not sure what regular python expression to use in order to achieve my desired outcome.

Userlevel 7
Badge +14

@DarkRoom 

Try asking ChatGPT for help with the regex to use in the Zap step.

Userlevel 1
Badge +1

I’m still having trouble. I want to create a new item in Monday.com for every specific word or phrase I look up. So in this exact instance, I would want 3 new items in Monday.com (because I was looking for EMB and there were 3 mentions of the word) all with the same Order Nickname found within the Printavo Trigger step. Is this doable?

Userlevel 7
Badge +14

@DarkRoom 

Yes it’s possible once you configure this Zap action correctly.

Zap action: Formatter > Text > Extract Pattern

 

Then the Looping app can be used to iterate: https://zapier.com/apps/looping/help

Userlevel 1
Badge +1

This is the result I get when using code to find a specific word.

 

And when I try and add it to the loop function (I’m using the create loop from line item option) the option for the previous step comes up

 

Also, how would I go about getting this integrated into Monday.com?

Userlevel 7
Badge +14

@DarkRoom 

We would need to see screenshots with how your Formatter step is configured to have context.

Userlevel 1
Badge +1

Hopefully this is what you’re looking for

 

 

Userlevel 7
Badge +14

@DarkRoom 

Try using a JavaScript Code step.

Then use this Zap action: Looping - Create Loop from Numbers

 

CONFIG

Set the Input Data values.

 

CODE

let text = inputData.text;
let match = inputData.match;
let count = countOccurrences(text, match);

function countOccurrences(text, match) {
// Use a regular expression with the global flag to find all occurrences
const regex = new RegExp(match, 'g');
const matches = text.match(regex);

// Return the number of matches (or 0 if there are no matches)
return matches ? matches.length : 0;
}

output = [{count, match, text}];

 

 

Userlevel 1
Badge +1

I’m not quite sure what I’m doing wrong so I’ll go over my entire process and then you can point out if something looks wrong.

  1. I start by setting the trigger. Steps 2-4 are related to something else and they’re working so please disregard them. 
  2. Step 5 looks like this: 

    This is the field I want to get the text from.

  3. This is the code that I use to try and extract all of the information I want (I know that this example doesn’t have some of these words. I’m generalizing it so that it can automate anything that comes my way).
  4. Finally this is the code that I use. Not exactly sure what it’s supposed to do.

  5. I’m at a loss for what I’m supposed to do. I have no background on any of this stuff. Hopefully this gives you more insight into what I’m working with. If not please let me know and I will show you.

Userlevel 7
Badge +14

@DarkRoom 

Try these Zap steps:

  1. Trigger: Printavo
  2. Action: Filter
  3. Action: Code
  4. Action: Looping - Create Loop from Numbers
  5. Action: Monday - Create Item

 

Not sure if you need any of the Formatter steps.

Userlevel 1
Badge +1

I think there’s one issue with the code. The text I’m searching is in line item form. Would this matter?

 

 

Userlevel 7
Badge +14

@DarkRoom

We would need to see screenshots with how your Code steps is configured and how your Zap steps are outlined now.

 

The match input is not meant to handle regex, rather just the single match term.

 

Userlevel 1
Badge +1

Okay that makes a bit more sense. How would I go about specifying what words I want to find? It could be a multitude of different things. Anything from SP-13 to HT 2 and Vinyl 4 to EMB 21 .

 

Here’s my steps. Set up to find an updated Invoice based off of a key word

 

Here’s how the code is set up.

 

This is a shot in the dark on how I would rectify the match input not handling code. Does this look right?

I would obviously add any words I want to find in similar fashion

Userlevel 7
Badge +14

@DarkRoom 

The code that was provide was only configured for the “match” input.

So the input for “match_1” won’t work unless the code is adjusted.

 

 

Userlevel 1
Badge +1

Is there any way I can have all of the words I want to find in one field? For example, SP-(0-9) (depending on what number is found), HT (0-9) and so on? or is the match only set up to handle one term?

Userlevel 7
Badge +14

@DarkRoom 

The custom Code is only configured to check for 1 “match” term.

If you are interested in having the Code configured to handle multiple terms, then you can submit a lead here: https://zapier.com/experts/automation-ace

Userlevel 1
Badge +1

@Troy Tessalone 

 

I have the code set up to search for multiple match fields. My question is: can I have one match field contain all of the words I want to find? It would be less effort on my part if I could have all of the words I want to find in one match field.

Example: match

SP-1, SP-2, SP-3 (and so on)

Instead of

match

SP-1

match_1

SP-2

(and so on)

Userlevel 7
Badge +14

@DarkRoom 

Yes, that’s possible, but the code needs to be reconfigured to handle multiple terms in for the “match” input.

Userlevel 1
Badge +1

How would I go about wording the match field for multiple words?

 

Also, I’m trying to see if the loop step works and I’m still only getting one item to be created. 

 

@Troy Tessalone 

Userlevel 7
Badge +14

@DarkRoom 

Make sure to review the help articles for using the Looping app in Zaps: https://zapier.com/apps/looping/help

 

If you are interested in having the Code configured to handle multiple terms, then you can submit a lead here: https://zapier.com/experts/automation-ace

Userlevel 1
Badge +1

I have the loop set up and everything is working as it should. Is there a way to assign specific names to a field in Monday.com per the results found?

What I mean is this: I have 3 matches found (SP-1, SP-2, SP-3) and I want the items that the loop makes to add SP-1, SP-2, SP-3 respectively so only one of these values is inputted per item made.

As it is now, only one value is being chosen (SP-1) and I’m left with 3 items with the same value in the field which is not what I want.

@Troy Tessalone

Userlevel 7
Badge +14

@DarkRoom 

We would need to see updated screenshots with how your Zap steps are configured to have true context.