[英]detecting emails inside an http header
i am building up a proxy in csharp and one of my tasks is to find emails inside an http header, problem is that inside the data that i get i receive %40 instead of @, could anyone please tell me how can i detect emails when the @ inside the mail address is being replaced with %40? 我正在csharp中建立一个代理,我的任务之一就是在http标头内找到电子邮件,问题是我收到的数据里面收到的是%40而不是@,有人可以告诉我如何才能检测到电子邮件邮件地址内的@被替换为%40? here is my code for getting email addresses inside a given string (with @ and not %40 instead) Code :
这是我在给定字符串中获取电子邮件地址的代码(使用@而不是%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);
}
Not sure if I understood your question. 不确定我是否理解你的问题。 Why don't you just replace
@
with %40
in regex you provided? 为什么不在你提供的正则表达式中用
@
%40
替换@
? So: 所以:
string regexPattern = @"[A-Za-z0-9._%-]+%40[A-Za-z0-9.-]+\.[A-Za-z]{2,4}";
URL decode your data before running it through the regex: 在通过正则表达式运行数据之前对URL进行解码 :
regex.Matches(this._context.Server.UrlDecode(this._context.Request.Headers[i]))
Or: 要么:
regex.Matches(HttpUtility.UrlDecode(this._context.Request.Headers[i]))
Use OR (|) to allow @ or "%40" 使用OR(|)允许@或“%40”
[A-Za-z0-9._%-]+(@|%40)[A-Za-z0-9.-]+.[A-Za-z]{2,4} [A-ZA-Z0-9 ._% - ] +。(@ |%40)[A-ZA-Z0-9 .-] + [A-ZA-Z] {2,4}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.