【发布时间】:2020-08-02 06:55:19
【问题描述】:
我正在处理一个包含 PII 信息的文本列表,这些信息被屏蔽为 XXXX XXXX,可以是电话号码或地址号码。我想取下面具。
x <- c('This is my phone number xxx xxx xxx', 'The account number is XXXXXXXXXX', 'Her age is xx', 'The credit number is xxxx xxxx xxxx xxxx', 'This is the list of accounts xxxxxxxxxxxx xxxxxxxxxxxx xxxxxxxxxxxx xxxxxxxxxxxx xxxxxxxxxxxx xxxxxxxxxxxx')
我写了这样的东西,但它并没有取代一切:
gsub("(?:\\s+|^)\\S*(?<!\\w)(?:xxxx?|xxxxxxxx)(?!\\w)\\S*", "", x, perl=TRUE)
如何改进此代码?
预期输出:
'这是我的电话号码', '帐号是', '她的年龄是', '信用号码是', '这是帐户列表'
【问题讨论】: