Skip to content

Instantly share code, notes, and snippets.

@alexfernandez803
Created August 21, 2017 23:21
Show Gist options
  • Select an option

  • Save alexfernandez803/2a3bc4fd1243fb7d97ebee41399e46ac to your computer and use it in GitHub Desktop.

Select an option

Save alexfernandez803/2a3bc4fd1243fb7d97ebee41399e46ac to your computer and use it in GitHub Desktop.
public string ExtractReply(string text, string address)
{
var regexes = new List<Regex>() { new Regex("From:\\s*" + Regex.Escape(address), RegexOptions.IgnoreCase),
new Regex("<" + Regex.Escape(address) + ">", RegexOptions.IgnoreCase),
new Regex(Regex.Escape(address) + "\\s+wrote:", RegexOptions.IgnoreCase),
new Regex("\\n.*On.*(\\r\\n)?wrote:\\r\\n", RegexOptions.IgnoreCase | RegexOptions.Multiline),
new Regex("-+original\\s+message-+\\s*$", RegexOptions.IgnoreCase),
new Regex("from:\\s*$", RegexOptions.IgnoreCase),
new Regex("^>.*$", RegexOptions.IgnoreCase | RegexOptions.Multiline)
};
var index = text.Length;
foreach(var regex in regexes){
var match = regex.Match(text);
if(match.Success && match.Index < index)
index = match.Index;
}
return text.Substring(0, index).Trim();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment