Skip to content

Instantly share code, notes, and snippets.

@LRENZ
Created February 3, 2021 04:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LRENZ/425d40e3ff4caa60488be033cd642cb4 to your computer and use it in GitHub Desktop.
Save LRENZ/425d40e3ff4caa60488be033cd642cb4 to your computer and use it in GitHub Desktop.
JS snippet to delete PII
function Pii(string){
var piiRegex = [{
name: 'EMAIL',
regex: /(\&|\?|\#)(email|e-mail|mail)=[^&#]+/gi
},{
name: 'EMAIL',
regex: /[^&?=#]+(@|%40)[^@&?=#]+\.[^@&?=#]+/gi
},{
name: 'ADDRESS',
regex: /(\&|\?|\#)address=[^&#]+/gi
},{
name: 'NAME',
regex: /(\&|\?|\#)(firstname|surname|prenom|lastname|name|nom|username)=[^&#]+/gi
},{
name: 'PASSWORD',
regex: /(\&|\?|\#)(password|pwd)=[^&#]+/gi
},{
name: 'PHONE',
regex: /(\&|\?|\#)phone=[^&#]+/gi
}];
try {
var val = decodeURIComponent(decodeURIComponent(string));
} catch(e) {
val = decodeURIComponent(string);
}
piiRegex.forEach(function(pii) {
if(val.match(pii.regex) !== null && val.match(pii.regex)[0].split('=').length > 1){
val = val.replace(pii.regex, val.match(pii.regex)[0].split('=')[0] + '=[DELETED ' + pii.name + ']');
}
else{
val = val.replace(pii.regex, '[DELETED ' + pii.name + ']');
}
});
return val
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment