public static void ParseMedalData(string Data, out MatchCollection MedalsMatches, out MatchCollection RanksMatches)
{
// Replace all Pythonic multi-line comments.
Data = Regex.Replace(Data, "\"\"\"(.*?)\"\"\"", "", RegexOptions.Multiline | RegexOptions.ExplicitCapture);
//Replace all Pythonic single-line comments.
Data = Regex.Replace(Data, "^#((!stop).)*$", "", RegexOptions.ExplicitCapture | RegexOptions.Multiline);
// Replace all spaces, tabs, newlines and carriage returns
Data = Data.Replace(" ", "").Replace("\t", "").Replace("\r", "").Replace("\n", "");
// Make sure this is a formated medal data file
if(!Data.Contains("#stop"))
throw new Exception("Improper Medal data file. Only medal data files generated with this program can be editied."
+ " Click the \"New\" button to generate a new medal data file, compatible with this editor.");
// Match and Capture awards and ranks
Match Medals = Regex.Match(Data, @"medal_data=\((?<Array>.*?)\)rank_data=", RegexOptions.IgnoreCase);
Match Ranks = Regex.Match(Data, @"rank_data=\((?<Array>.*?)\)#end", RegexOptions.IgnoreCase);
// Make sure we have captures, otherwise its a parse error
if (!Medals.Success || !Ranks.Success)
throw new ParseException();
// Caputre all awards
string pattern = "\\(['|\"](?<MedalIntId>[0-9]{7}(_[0-3])?)['|\"],"
+ "['|\"](?<MedalStrId>.*?)['|\"],"
+ "(?<RewardType>[0-2]),"
+ "(?<Conditions>[a-z]+_[a-z]+\\(.*?\\))\\),#stop";
MedalsMatches = Regex.Matches(Medals.Groups["Array"].Value, pattern, RegexOptions.ExplicitCapture);
// Capture all Ranks
pattern = "\\((?<RankId>[0-9]+),'rank',(?<Conditions>[a-z]+_[a-z]+\\(.*?\\))\\),#stop";
RanksMatches = Regex.Matches(Ranks.Groups["Array"].Value, pattern, RegexOptions.ExplicitCapture | RegexOptions.Multiline);
}