首页 新闻 赞助 找找看

C# 使用regex.replace 正则替换邮箱@前3位为星号

0
[已解决问题] 解决于 2015-10-14 17:17

C# 使用regex.replace 正则替换邮箱@前3位为星号

比如有一段话:飞机拉萨觉得eeerff@126.com,浪费卡就上了多久5345345@qq.com,我要替换成

飞机拉萨觉得eee***@126.com,浪费卡就上了多久5345***@qq.com

生活无限的主页 生活无限 | 初学一级 | 园豆:6
提问于:2015-10-14 16:54
< >
分享
最佳答案
1

大概是这样:

string s = @"飞机拉萨觉得eeerff@126.com,浪费卡就上了多久5345345@qq.com";
string res = Regex.Replace(s,@"\w{3}(?=@\w+?.com)","***");

pattern 中的\w 还可以更精确点(限定为字母数字下划线之类的)

奖励园豆:5
clarlespeng | 菜鸟二级 |园豆:469 | 2015-10-14 17:11

非常感谢

生活无限 | 园豆:6 (初学一级) | 2015-10-14 17:16
其他回答(1)
0
            string content = "飞机拉萨觉得eeerff@126.com,浪费卡就上了多久5345345@qq.com";
            string pattern = "\\w{3}(?=@\\w+?.com)";
            string result = Regex.Replace(content, pattern, "***");
            Console.WriteLine(result);
            Console.ReadKey();
上位者的怜悯 | 园豆:172 (初学一级) | 2015-10-14 17:11

感谢

支持(0) 反对(0) 生活无限 | 园豆:6 (初学一级) | 2015-10-14 17:17
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册