Skip to main content
Best answer

How can I return all regex matches in one spreadsheet row ?

  • August 19, 2020
  • 1 reply
  • 193 views

Hi ! 

I’m trying to extract all the words that matches a pattern from a string, but with Formatter I only have the first match. 

Here is my string (don’t mind ‘3 dirigeants’, I used another regex for that one)

3 dirigeants
Vendredi : 2, Jeudi : 1, Mercredi : 3, Mardi : 1

I used 2 regular expressions as I want to have the numbers in a row and the 4 last words in another row.

This is the first regex for the numbers (2, 1, 3, 1) :

(?<= : )\d+

And this is the one for the words (Vendredi, Jeudi, Mercredi, Mardi :

(\w+)(?= :)

But as I said, it only returns the first match for both. So I tried to code instead but I don’t know much about Python… this is what I have so far but I guess it is all wrong as it doesn’t work.

 

By any chance, can someone know how I can solve my problem ?

 

Thank you very much for your help.

Best answer by andywingraveBest answer by andywingrave

Hey. I think you need to chop the elephant up a little more here before you can apply the REGEX.

Here’s a really badly written code (JavaScript) step which solves it in a different way - by first creating two arrays before applying the regex

var string = inputData.input
var words = string.split(',')
var days = []
var numbers = []
for(var i = 0; i < words.length; i++)
{
    days[i] = words[i].replace(/[^A-Za-z]/g, "");
}

for(var i = 0; i < words.length; i++)
{
    numbers[i] = words[i].replace(/\D/g, "");
}

output = [{longString: string, days, numbers}];

The core of this is, I’ve split the strings up into two arrays - Returned only letters in one, and only numbers in the other

Hope that helps!

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.

1 reply

andywingrave
Forum|alt.badge.img+9
  • Zapier Expert
  • 854 replies
  • Answer
  • August 26, 2020

Hey. I think you need to chop the elephant up a little more here before you can apply the REGEX.

Here’s a really badly written code (JavaScript) step which solves it in a different way - by first creating two arrays before applying the regex

var string = inputData.input
var words = string.split(',')
var days = []
var numbers = []
for(var i = 0; i < words.length; i++)
{
    days[i] = words[i].replace(/[^A-Za-z]/g, "");
}

for(var i = 0; i < words.length; i++)
{
    numbers[i] = words[i].replace(/\D/g, "");
}

output = [{longString: string, days, numbers}];

The core of this is, I’ve split the strings up into two arrays - Returned only letters in one, and only numbers in the other

Hope that helps!