Best answer

Using Wildcards in Text Replace

  • 30 March 2020
  • 7 replies
  • 1187 views

Userlevel 1

So I have the goal of sending a list of all rows in a google sheet that meet a certain condition as a message in Slack, 

 

So far all is good except for one small formatting annoyance

“COL$B: This is a message
COL$C: This is a URL
id: 51
row: 51

COL$B: This is a message
COL$C: This is a URL
id: 103
row: 103”

As you can see the COL$ and the id and row are unnecessary for the message, is there a way in the find replace to use wildcards so I can remove the COL$[character] and the id and row lines?

icon

Best answer by ikbelkirasan 9 April 2020, 19:28

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.

7 replies

Userlevel 7
Badge +12

Hi @JHaynes Thanks for your question!

 

Could you please show us what your Slack step looks like - specifically, could you take a screenshot of the message field so we can see what’s there? If the screenshot includes private data, don’t forget to obscure that before adding it to your post, thanks!

Userlevel 1

Hi @Danvers, Thanks for the response,

Here is a screenshot of the output to slack

What I have done so far, grab a list from the googlesheet of all the rows that meet the criteria, Used line item to text because I was getting multiple copies of the same message, And this is what I am left with The goal for the output message is to remove: “COL$B:”, “COL$C”:, the id line, and the row line. The way I removed the COL$A field was by using text replace with nothing, since that line was a static line to begin with

 

 

Userlevel 7
Badge +12

Hi @JHaynes I’m sorry for the delay in getting back to you on this!

 

Thanks for the screenshot, I can see what you’re saying now.  The answer is that there isn’t a shortcut here I’m afraid. You would need to have a Formatter step to remove the text for ‘COL$A’, B and C separately. Sorry about that!

Userlevel 1

Hi @Danvers,

I was more concerned about removing the ID and Row lines as I could remove the COLA and B  C separately no problem but the lines with ID and Row consistently change its not a huge issue in the long run but just a perfectionist within me

Userlevel 7
Badge +12

Ah, I’m with you. And yes, unfortunately you can’t use wildcards in the replace action. 

 

The only way that I can think to do it would be using a few Formatter/Split Text steps, but that would only work if you had the same number of tasks (rows) each time the Zap fires. Sorry there’s not a better solution here!

Userlevel 7
Badge +12

Hey @JHaynes and @Danvers - While it might not be possible to do it with a Formatter step, you might want to try the following in a code step and see if it does the trick. The text should be mapped to an input field called “text”.

const { text } = inputData;

const outputLines = [];

text.split("\n").forEach((line) => {
if (/^(id|row): \d+/.test(line) === false) {
const result = line.replace(/^COL\$.:/g, "").trim();
outputLines.push(result);
}
});

output = [
{
text: outputLines.join("\n")
}
];

 

Userlevel 1

That definitely did the trick in 1 Thanks so much!