Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

136
Visualizações
filter google sheet based on cell value using a regex expression that match any numeric values and a specific string

Below is a code that filters spreadsheet based on specific column values and copy matches to a new spreadsheet

function filterkhaled(){
    var sheet = SpreadsheetApp.getActiveSheet();
    var newSheet = SpreadsheetApp.getActiveSpreadsheet().insertSheet();
    var reg = /^\d+$/;
    var data = sheet.getDataRange().getDisplayValues();
    var newData = data.filter(row => ["yes"].includes(row[12]) | row.match(reg));
    newSheet.getRange(1,1,newData.length,newData[0].length).setValues(newData);
  }

I want basically that filter matches the string "yes" or any numeric value, and then copy the corresponding matches into new spreadsheet. The code here row.match(reg)shows the following error TypeError: row.match is not a function is there a way to make the regex filter work?

Here is how the starting table look like source sheet, where green marked rows are to be copied to a new spreadsheet based on the value of column M

The output shall contain all green rows.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Modification points:

  • I thought that the reason for your error of TypeError: row.match is not a function is due to that row is an array.
  • ["yes"].includes(row[12]) is the same with row[12] == "yes".
  • In this case, please use || instead of |.

When these points are reflected in your script, it becomes as follows.

Modified script:

function filterkhaled() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var newSheet = SpreadsheetApp.getActiveSpreadsheet().insertSheet();
  var reg = /^\d+$/;
  var data = sheet.getDataRange().getDisplayValues();
  var newData = data.filter(row => row[12] == "yes" || row[12].match(reg));
  if (newData.length == 0) return;
  newSheet.getRange(1, 1, newData.length, newData[0].length).setValues(newData);
}
  • When this script is run, the rows that the value of column "M" is yes or the number are put to the new sheet.

References:

  • match()
  • Logical OR (||)
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda