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? here is my code for getting email addresses inside a given string (with @ and not %40 instead) Code :
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? 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:
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"
[A-Za-z0-9._%-]+(@|%40)[A-Za-z0-9.-]+.[A-Za-z]{2,4}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.