Simple data anonymization: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
No edit summary |
||
| Line 2: | Line 2: | ||
Simple data anonymization 使用 Excel 或 MySQL 資料庫查詢方式,做簡易個資去識別化 | Simple data anonymization 使用 Excel 或 MySQL 資料庫查詢方式,做簡易個資去識別化 | ||
== case1: 王小明 --> 王O明 == | |||
== case1: 王小明 --> 王OO == | |||
ex: | |||
* 王小明 --> 王OO | |||
* 複姓小英 --> 複OO | |||
作法 | |||
* Excel: | |||
** {{kbd | key=<nowiki>=REPLACE(A2, 2, LEN(A2)-1, "OO")</nowiki>}} also applied for 3 or 4 words | |||
** {{kbd | key=<nowiki>=REPLACE(A2, 2, 2, "O")</nowiki>}} {{exclaim}} only applied for 3 words, NOT for 4 words | |||
* MySQL: {{kbd | key=<nowiki>SELECT CONCAT(LEFT("王小明", 1), 'OO')</nowiki>}} | |||
== case2: 王小明 --> 王O明 == | |||
ex: 王小明 --> 王O明 | ex: 王小明 --> 王O明 | ||
* Excel: | * Excel: | ||
| Line 21: | Line 35: | ||
</pre> | </pre> | ||
reference | reference | ||
Revision as of 18:15, 28 July 2016
Simple data anonymization 使用 Excel 或 MySQL 資料庫查詢方式,做簡易個資去識別化
case1: 王小明 --> 王OO
ex:
- 王小明 --> 王OO
- 複姓小英 --> 複OO
作法
- Excel:
- =REPLACE(A2, 2, LEN(A2)-1, "OO") also applied for 3 or 4 words
- =REPLACE(A2, 2, 2, "O")
only applied for 3 words, NOT for 4 words
- MySQL: SELECT CONCAT(LEFT("王小明", 1), 'OO')
case2: 王小明 --> 王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]
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));
reference
further reading