Skip to main content
Best answer

Remove blank comma/space from lists

  • October 7, 2021
  • 3 replies
  • 1886 views

My trigger action provides Zapier with a few simple lists of data, but sometimes entries in these lists are blank. I use a formatter step to combine a few of these lists into one string of text. When I use this string in later steps, I often end up with a few instances of “comma space” or “, “ repeating next to each other, from blank entries in the previous lists.

Here’s an example of a string of text I will end up with after my Formatter step:
“Customizations: , , , , , , , Screen printing, 289+ pieces, Full Front , Other Small little logo on bottom of left side”

What’s the easiest way (read: fewest steps) to strip these useless blank “comma space” repeaters from this string? 

I know I can do Find>Replace as a Formatter step, but I’ll have to do one step for find “, , “ replace with “ “, then another step for find “, , , “ replace with “ “, etc. I tried using a Lookup Table to offer multiple strings to replaced in one step, but couldn’t get that to work properly.

Any suggestions are appreciated! 

Best answer by Troy TessaloneBest answer by Troy Tessalone

Hi @IdleWilde Printing 

A code step can be used with RegEx to find/replace all instances of repeating commas.

Code: https://zapier.com/apps/code/help

replace(): https://www.w3schools.com/jsref/jsref_replace.asp

 

 

Give this JavaScript code a try...

let INPUT = inputData.INPUT;

let OUTPUT = INPUT.replace(/ ,/g,',').replace(/,,/g,'').replace(/:,/g,':').trim();

output = [{INPUT, OUTPUT}];

 

View original
Did this topic help you find an answer to your question?
This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

3 replies

Troy Tessalone
Forum|alt.badge.img+14
  • Zapier Expert
  • 31284 replies
  • Answer
  • October 7, 2021

Hi @IdleWilde Printing 

A code step can be used with RegEx to find/replace all instances of repeating commas.

Code: https://zapier.com/apps/code/help

replace(): https://www.w3schools.com/jsref/jsref_replace.asp

 

 

Give this JavaScript code a try...

let INPUT = inputData.INPUT;

let OUTPUT = INPUT.replace(/ ,/g,',').replace(/,,/g,'').replace(/:,/g,':').trim();

output = [{INPUT, OUTPUT}];

 


Troy Tessalone wrote:

Hi @IdleWilde Printing 

A code step can be used with RegEx to find/replace all instances of repeating commas.

Code: https://zapier.com/apps/code/help

 

 

Thanks for the quick response and the suggestion, Troy. Trying to figure this out now.

I’m getting some errors from Zapier which I think is solely based on formatting/my lack of Javascript knowledge. I’m sure it’s a simple formatting issue I’m overlooking, can anyone help? I thought “lists” would be defined in the first part of mapping it to a data set, however I keep getting errors that it is undefined?


Sorry, looks like you added more info to your post since I started quoting. I think I have enough info now to figure this out. Thanks for your help.