Best answer

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

  • 19 August 2020
  • 1 reply
  • 100 views

Userlevel 2

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.

icon

Best answer by andywingrave 26 August 2020, 23:22

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

This topic has been closed for comments

1 reply

Userlevel 7
Badge +9

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!