Created
August 21, 2017 23:21
-
-
Save alexfernandez803/2a3bc4fd1243fb7d97ebee41399e46ac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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