使用regex只返回数字,然后进行计数。如果4个或更多,请删除:
function removeKeywords() {
var sheet = SpreadsheetApp.getActiveSheet();
var rows = sheet.getDataRange();
var numRows = rows.getNumRows();
var values = rows.getValues();
var rowsDeleted = 0;
for (var i = 0; i <= numRows - 1; i++) {
var row = values[i];
if (row[0].toLowerCase().indexOf("robot") > -1) {
sheet.deleteRow((parseInt(i)+1) - rowsDeleted);
rowsDeleted++;
}
var str=row[0].replace(/\D/g, '')//extract the numbers
var len=str.length // determine lenght of number string
if(len >=4 ){ //if 4 or more numbers delete
sheet.deleteRow((parseInt(i)+1) - rowsDeleted);
rowsDeleted++;
}
}}