[不是问题]编写使用电子邮件替换电子邮件的正则表达式 [英] [Not a question] Write Regular expression that replaces email with Email
本文介绍了[不是问题]编写使用电子邮件替换电子邮件的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
编写一个正则表达式,可以用[EMAIL]替换文本中的所有电子邮件:
" Christian有christian@email.com。 Olof的电子邮件是olof@gmail.com。 Lars有电子邮件britt123@oxford.co.uk."
我该怎么办?
Write a regular expression that can replace all emails in text with "[EMAIL]":
"Christian has christian@email.com. Olof has the email olof@gmail.com. Lars has the emai britt123@oxford.co.uk."
How should i do this?
推荐答案
试试这个:
Try this:
string textWithEmails = "Christian has christian@email.com. Olof has the email olof@gmail.com. Lars has the emai britt123@oxford.co.uk.";
string filteredStr = Regex.Replace(textWithEmails, @"([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})", "[EMAIL]");
Console.WriteLine(filteredStr);
我使用的正则表达式是来自正则表达式库的快餐 [ ^ ]
这是一个相当完整的正则表达式,但不是100%完成。有关完整的电子邮件正则表达式,请查看此处:
http:// ex-parrot.com/~pdw/Mail-RFC822-Address.html [ ^ ]
这很简单,请参阅MSDN [ ^ ]文件。
-KR
It's pretty simple, See the MSDN[^] documentation.
-KR
这篇关于[不是问题]编写使用电子邮件替换电子邮件的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文