Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

132
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda