public static string MoveExternalLinks(string articleText)
{
string articleTextAtStart = articleText;
// is external links section above references?
Match elm = ExternalLinksSection.Match(articleText);
string externalLinks = elm.Groups[1].Value;
// validate no <ref> in external links section
if (!elm.Success || Regex.IsMatch(externalLinks, WikiRegexes.ReferenceEnd))
return articleTextAtStart;
string references = ReferencesSection.Match(articleText).Groups[1].Value;
// references may be last section
if (references.Length == 0)
references = ReferencesToEnd.Match(articleText).Value;
if (references.Length > 0 && elm.Index < articleText.IndexOf(references))
{
articleText = articleText.Replace(externalLinks, "");
articleText = articleText.Replace(references, references + externalLinks);
}
return articleText;
}