Simple data anonymization: Difference between revisions

From LemonWiki共筆
Jump to navigation Jump to search
No edit summary
mNo edit summary
Line 1: Line 1:


Simple data anonymization  
Simple data anonymization 簡易個資去識別化


== case1: 王小明 --> 王O明 ==
== case1: 王小明 --> 王O明 ==

Revision as of 13:44, 3 December 2015

Simple data anonymization 簡易個資去識別化

case1: 王小明 --> 王O明

ex: 王小明 --> 王O明

  • Excel:
    • =REPLACE(A2, 2, LEN(A2)-2, O) also applied for 3 or 4 words ex: 王王小明 -> 王O明
    • =REPLACE(A2, 2, 1, O)[1] Icon_exclaim.gif only applied for 3 words, NOT for 4 words
  • PHP: using regular_replace
$string = '王小明';
$pattern = '/^(\X)(\X)(\X+)/u';
$replacement = '$1O$3';
echo preg_replace($pattern, $replacement, $string);
  • MySQL: using SUBSTRING
SELECT CONCAT(SUBSTRING_INDEX('王小明', SUBSTRING('王小明', 2, 1), 1), 
SUBSTRING('王小明', 2, 1),
SUBSTRING_INDEX('王小明', SUBSTRING('王小明', 2, 1), -1));

case2: 王小明 --> 王OO

ex: 王小明 --> 王OO

  • Excel:
    • =REPLACE(A2, 2, LEN(A2)-1, O) also applied for 3 or 4 words ex: 王王小明 -> 王OO
    • =REPLACE(A2, 2, 2, O) Icon_exclaim.gif only applied for 3 words, NOT for 4 words
  • MySQL: SELECT CONCAT(LEFT("王小明", 1), 'OO')

reference

further reading