[英]detecting emails inside an http header
我正在csharp中建立一个代理,我的任务之一就是在http标头内找到电子邮件,问题是我收到的数据里面收到的是%40而不是@,有人可以告诉我如何才能检测到电子邮件邮件地址内的@被替换为%40? 这是我在给定字符串中获取电子邮件地址的代码(使用@而不是%40) 代码 :
string regexPattern = @"[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}";
Regex regex = new Regex(regexPattern);
MatchCollection matches = regex.Matches(this._context.Request.Headers[i]);
foreach (Match match in regex.Matches(this._context.Request.Headers[i]))
{// any email address should be printed
Console.WriteLine(match.Value);
}
不确定我是否理解你的问题。 为什么不在你提供的正则表达式中用@
%40
替换@
? 所以:
string regexPattern = @"[A-Za-z0-9._%-]+%40[A-Za-z0-9.-]+\.[A-Za-z]{2,4}";
在通过正则表达式运行数据之前对URL进行解码 :
regex.Matches(this._context.Server.UrlDecode(this._context.Request.Headers[i]))
要么:
regex.Matches(HttpUtility.UrlDecode(this._context.Request.Headers[i]))
使用OR(|)允许@或“%40”
[A-ZA-Z0-9 ._% - ] +。(@ |%40)[A-ZA-Z0-9 .-] + [A-ZA-Z] {2,4}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.