有时,我的电子邮件列表包含同一个人的重复地址。例如,Jane 的地址都是“[电子邮件受保护]”和“doe.jane@email”。她的变体包括替换“.”。与“-”或“_”。目前,我的重复脚本(由@Jordan Running 和 Ed Nelson 精心升级)可以处理“严格”重复,但无法检测到“[电子邮件受保护]”是“[电子邮件受保护]”。有没有一种方法可以删除这些重复项,这样我就不会向 Jane 的多个地址发送电子邮件?它们都指向同一个收件箱,因此我只需包含她的地址之一。
这是我当前的代码:
function removeDuplicates() {
const startTime = new Date();
const newData = [];
const sheet = SpreadsheetApp.getActiveSheet();
const data = sheet.getDataRange().getValues();
const numRows = data.length;
const seen = {};
for (var i = 0, row, key; i < numRows && (row = data[i]); i++) {
key = JSON.stringify(row);
if (key in seen) {
continue;
}
seen[key] = true;
newData.push(row);
};
sheet.clearContents();
sheet.getRange(1, 1, newData.length, newData[0].length).setValues(newData);
// Show summary
const secs = (new Date() - startTime) / 1000;
SpreadsheetApp.getActiveSpreadsheet().toast(
Utilities.formatString('Processed %d rows in %.2f seconds (%.1f rows/sec); %d deleted',
numRows, secs, numRows / secs, numRows - newData.length),
'Remove duplicates', -1);
}
备注:
@email.com
部分的情况下使用,会扭曲结果=removeDuplicatesFuzzy(B2:B12,0.66)
0.66
是模糊匹配的百分比。-
是指未找到匹配项(“唯一”值)您可以尝试这个库: https://github.com/Glench/fuzzyset.js
要安装它,请复制代码从这里。
使用方法很简单:
function similar_test(string1, string2)
{
string1 = string1 || '[email protected]';
string2 = string2 || '[email protected]'
a = FuzzySet();
a.add(string1);
var result = a.get(string2);
Logger.log(result); // [[0.6666666666666667, [email protected]]]
return result[0][0]; // 0.6666666666666667
}
这里还有更多信息:https://glench.github.io/fuzzyset.js/
备注:
[email protected]
,那么它与 [email protected]
的相似度为 84%,但人类会检测到它完全是另一个人。搜索我的 Google Sheets 插件 Flookup。它应该做你想做的事。
对于您的情况,您可以使用此功能:
ULIST(colArray, [threshold])
参数详情为:
colArray
:要从中返回唯一值的列。threshold
:不唯一的 colArray 值之间的最小相似度百分比。或者您可以简单地使用附加菜单中的突出显示重复项或删除重复项。 主要功能是您可以通过更改相似度百分比来调整严格程度。
奖励:它将很容易捕获像
[email protected]
/ [email protected]
这样的交换
您可以在官方网站了解更多信息。