User:Lightmouse/AWB/scripts/all dates to dmy

//all dates to dmy

//

        WikiFunctions.Parse.HideText ht = new WikiFunctions.Parse.HideText(true, false, true);

        public string ProcessArticle(string ArticleText, string ArticleTitle, int wikiNamespace, out string Summary, out bool Skip)
        {
            Skip = false;
            Summary = "";

ArticleText = ht.Hide(ArticleText);

//protect dates
    //retraining redirects containing a date and some text
    //regex(/(\[\[)(?:September 3 Society)(\]\]|\|)/gi, '$1Jiusan Society$2');
    //regex(/(\[\[)(?:June 4th incident)(\]\]|\|)/gi, '$1Tiananmen Square protests of 1989$2');
 
    //protect all links containing a date and some text
    //regex(/(\[\[)(\s*\w[^\]\|\n]+?@day[^\]\|\n]+?@fullmonth[^\]\|\n]*)(\]\]|\|)", "$1♫$2");
    //regex(/(\[\[)([^\]\|\n]*?@day[^\]\|\n]+?@fullmonth(?:,? @year|) \D[^\]\|\n]+\w\s*)(\]\]|\|)", "$1♫$2");
    //regex(/(\[\[)(\s*\w[^\]\|\n]+?@fullmonth[^\]\|\n]+?@day[^\]\|\n]*)(\|)", "$1♫$2");
    //regex(/(\[\[)([^\]\|\n]*?@fullmonth[^\]\|\n]+?@day(?:, @year|) \D[^\]\|\n]+\w\s*)(\]\]|\|)", "$1♫$2");
 
    //protects certain links
    //regex(/(\[\[4)(AD)", "$1♫$2");
    //regex(/(March )((?:8|14) Alliance)", "$1♫$2");
    //regex(/(23rd )(March 1931: Shaheed)", "$1♫$2");
    //regex(/(Long March )([1-7])", "$1♫$2");
    //regex(/(movement 2 )(June)", "$1♫$2");
    //regex(/(6th\sof )(October City)", "$1♫$2");
    //regex(/(Party Workers' Liberation Front 30th of )(May)", "$1♫$2");
    //regex(/(4th\sof )(August regime)", "$1♫$2");
    //regex(/(19th\sof )(April movement)", "$1♫$2");
    //regex(/(\[July )(31st \(film\))", "$1♫$2");
    //regex(/(\[\[)(13 )(May incident)(\|)", "$1♫$2");
    //regex(/(\[\[)(November )(1828)(\]\])", "$1♫$2");
    //regex(/(4th\sof )(July)", "$1♫$2");
    //regex(/(\[\[)((?:2300|2000)\s?)(AD)(\]\])", "$1♫$2");
 
    // works names
    //regex(/(protect string)", "$1♫$2");
    //regex(/(11\/22\/63)", "$1♫$2");
    //regex(/(1\.1\.1994)", "$1♫$2");
    //regex(/(4th of July, Asbury)", "$1♫$2");
    //regex(/((?:\[\[|\'\')June)( 1, 1974)(?=[\]\'])", "$1♫$2");
    //regex(/((?:\[\[|\'\')July)( 15, 1972)(?=[\]\'])", "$1♫$2");
    //regex(/(Les Bains Douches 18)( December 1979)", "$1♫$2");
    //regex(/(August)( 7, 4:15)", "$1♫$2");
    //regex(/(In Concert, Zürich, October)( 28, 1979)", "$1♫$2");
    //regex(/(CBGB OMFUG Masters: Live June)( 29, 2001)", "$1♫$2");
    //regex(/(Live at [^\|\]]* [1-3]\d)( @fullmonth)/gi, "$1♫$2");
    //regex(/(Live at [^\|\]]* @fullmonth)( @dd)/gi, "$1♫$2");

//fix common errors
//month+day piped to month+day
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[\d{1,2}(?:th|st|nd|rd|)\s(?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\|(\d{1,2}\s)(?:th|st|nd|rd|)(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\]\]", "[[$1$2]]");
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[(?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\s\d{1,2}(?:th|st|nd|rd|)\|(\d{1,2}\s)(?:th|st|nd|rd|)(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\]\]", "[[$1$2]]");
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[\d{1,2}\s(?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\|(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)(\s\d{1,2})(?:th|st|nd|rd|)\]\]", "[[$1$2]]");
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[(?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\s\d{1,2}(?:th|st|nd|rd|)\|(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)(\s\d{1,2})(?:th|st|nd|rd|)\]\]", "[[$1$2]]");

//month+day piped to number
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[\d{1,2}(?:th|st|nd|rd|)\s(?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\|(\d{1,4})\]\]", "[[$1]]");
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[(?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\s\d{1,2}(?:th|st|nd|rd|)\|(\d{1,4})\]\]", "[[$1]]");

//fix 'bda' template redirect
ArticleText=Regex.Replace(ArticleText, @"(?i){{bda\|([^}]+)}}", "{{birth date and age|$1}}");

ArticleText=Regex.Replace(ArticleText, @"(?i)(\[\[)\s([^\]]*\]\])", "$1$2");
ArticleText=Regex.Replace(ArticleText, @"(?i)(\[\[[^\]\|]*)\s(\]\])", "$1$2");
ArticleText=Regex.Replace(ArticleText, @"(?i)(\[\[[^\]]*\s)\s+([^\]]\]\])", "$1$2");
ArticleText=Regex.Replace(ArticleText, @"(?i)(\[\[[^\]]*\d),(\]\])", "$1$2");

//part dates

//remove leading zeros from dts templates
ArticleText=Regex.Replace(ArticleText, @"(?i)({{dts\d?\|[^}]*\|)0([^}]*}})", "$1$2");

//delink ISO dates
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[(\d{4}-\d\d-\d\d)\]\]", "$1");
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[(\d{4})\]\]-\[\[(\d\d-\d\d)\]\]", "$1-$2");
ArticleText=Regex.Replace(ArticleText, @"(?i)(\d{4})-\[\[(\d\d-\d\d)\]\]", "$1-$2");
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[(\d{4})\]\]-(\d\d-\d\d)", "$1-$2");

//remove templates that links launch year, baseball year etc
//ArticleText=Regex.Replace(ArticleText, @"(?i){{(?:avyear|by|fy|ly|scy|sdy)\|(\d{1,4})}}", "$1");

//remove dts1 template that links ISO dates
ArticleText=Regex.Replace(ArticleText, @"(?i){{dts1\|(\d{4}-\d\d-\d\d)}}", "$1");

// century
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[((?:first|second|third|fourth|fifth|sixth|seventh|eighth|ninth|tenth|eleventh|twelfth|thirteenth|fourteenth|fifteenth|sixteenth|seventeenth|eighteenth|nineteenth|twentieth|twenty(?:\s|-)first)(?:\s|-))century\]\]", "$1century");
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[((?:first|second|third|fourth|fifth|sixth|seventh|eighth|ninth|tenth|eleventh|twelfth|thirteenth|fourteenth|fifteenth|sixteenth|seventeenth|eighteenth|nineteenth|twentieth|twenty(?:\s|-)first)(?:\s|-))century\s(AD|BC|CE|BCE)\]\]", "$1century");
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[(\d{1,2}(?:st|nd|rd|th)(?:\s|-))century\]\]", "$1century");
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[(\d{1,2}(?:st|nd|rd|th)(?:\s|-))centuries\]\]", "$1centuries");
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[\d{1,2}(?:st|nd|rd|th)(?:\s|-)century\|(\d{1,2}(?:st|nd|rd|th))\]\]", "$1");
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[\d{1,2}(?:st|nd|rd|th)(?:\s|-)century\|(\d{1,2}(?:st|nd|rd|th)(?:\s|-))century\]\]", "$1century");
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[\d{1,2}(?:st|nd|rd|th)(?:\s|-)century\|(\d{1,2}(?:st|nd|rd|th)(?:\s|-))centuries\]\]", "$1centuries");
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[(\d{1,2}(?:st|nd|rd|th)(?:\s|-))century\s(AD|BC|CE|BCE)\]\]", "$1century $2");
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[\d{1,2}(?:st|nd|rd|th)(?:\s|-)century\|(\d{1,2}(?:st|nd|rd|th)(?:\s|-))century\s(AD|BC|CE|BCE)\]\]", "$1century $2");
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[\d{1,2}(?:st|nd|rd|th)(?:\s|-)century\|(\d{1,2}(?:st|nd|rd|th)(?:\s|-))centuries\s(AD|BC|CE|BCE)\]\]", "$1centuries $2");

//Protect 2000 AD etc
ArticleText=Regex.Replace(ArticleText, @"(?i)(\[\[(?:2300|2000))\s(AD\]\])", "$1xx$2");

// decades and years
ArticleText=Regex.Replace(ArticleText, @"\[\[(\d{1,3}0)\'?s\]\]", "$1s");
ArticleText=Regex.Replace(ArticleText, @"\[\[\d{1,3}0\'?s?\|([^\]]{1,30})\]\]", "$1");
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[(\d{1,3}0)\'?(s)?\s(AD|BC|CE|BCE)\]\]", "$1$2 $3");
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[\d{1,3}0\'?s?\s(?:AD|BC|CE|BCE)\|([^\]]{1,30})\]\]", "$1");


// solitary day_numbers
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[(?:January|February|March|April|May|June|July|August|September|October|November|December)\s\d{1,2}(?:th|st|nd|rd)\|(\d{1,2}(?:th|st|nd|rd))\]\]", "$1");
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[\d{1,2}(?:th|st|nd|rd)\s(?:January|February|March|April|May|June|July|August|September|October|November|December)\|(\d{1,2}(?:th|st|nd|rd))\]\]", "$1");
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[(\d{1,2}(?:st|nd|rd|th))\]\]", "$1");

//Unprotect 2000 AD etc
ArticleText=Regex.Replace(ArticleText, @"(?i)(\[\[(?:2300|2000))xx(AD]\])", "$1 $2");

//month+year
//Identify surprise or 'Easter egg' diversions linking month+years to year articles. Turn them into month+year links to be dealt with below
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[\d{1,4}#[^\|\]]+\|((?:January|February|March|April|May|June|July|August|September|October|November|December)\s\d{3,4})\]\]", "[[$1]]");
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[((?:January|February|March|April|May|June|July|August|September|October|November|December)\s\d{3,4})\]\]", "$1");

//removed piped years when in full date
ArticleText=Regex.Replace(ArticleText, @"(?i)(\[\[\d{1,2}\s(?:January|February|March|April|May|June|July|August|September|October|November|December)\]\],?\s?\[\[)[^\|\]]{1,32}\|(\d{1,4}\]\])", "$1$2");
ArticleText=Regex.Replace(ArticleText, @"(?i)(\[\[(?:January|February|March|April|May|June|July|August|September|October|November|December)\s\d{1,2}\]\],?\s?\[\[)[^\|\]]{1,32}\|(\d{1,4}\]\])", "$1$2");

//remove 'xx' left by other code
ArticleText=Regex.Replace(ArticleText, @"(?i)(in)xx((?:aviation|baseball|film|literature|comics|ireland))", "$1 $2");

//'present'
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[Present\s\(time\)\|(Present)\]\]", "$1");
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[(Present)\]\]", "$1");

//Season
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[(spring\s\(season\)|summer|winter|autumn)\]\]", "$1");
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[spring\s\(season\)\|(spring)\]\]", "$1");

//Identify surprise or 'Easter egg' diversions linking months to year articles.
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[\d{1,4}#[^\|\]]+\|(January|February|March|April|May|June|July|August|September|October|November|December)\]\]", "$1");

// months
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[\s?(January|February|March|April|May|June|July|August|September|October|November|December)\s?\]\]", "$1");
ArticleText=Regex.Replace(ArticleText, @"\[\[(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\]\]", "$1");
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[(?:January|February|March|April|May|June|July|August|September|October|November|December)\|(January|February|March|April|May|June|July|August|September|October|November|December)\]\]", "$1");
//Treat 'Sept' (i.e. month abbreviation) differently from 'sept' (i.e. family)
ArticleText=Regex.Replace(ArticleText, @"\[\[(Sept)\]\]", "$1");
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[January\|(Jan)\]\]", "$1");
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[February\|(Feb)\]\]", "$1");
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[March\|(Mar)\]\]", "$1");
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[April\|(Apr)\]\]", "$1");
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[May\|(May)\]\]", "$1");
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[June\|(Jun)\]\]", "$1");
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[July\|(Jul)\]\]", "$1");
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[August\|(Aug)\]\]", "$1");
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[September\|(Sep)\]\]", "$1");
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[October\|(Oct)\]\]", "$1");
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[November\|(Nov)\]\]", "$1");
ArticleText=Regex.Replace(ArticleText, @"\[\[December\|(Dec)\]\]", "$1");

//month piped to number
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[(?:January|February|March|April|May|June|July|August|September|October|November|December)\|(\d{1,4})\]\]", "$1");

//Month+day_number "March 7th" -> "March 7"
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[(January|February|March|April|May|June|July|August|September|October|November|December)\s(\d?\d)(?:th|st|nd|rd)\]\]", "[[$1 $2]]");
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[((?:January|February|March|April|May|June|July|August|September|October|November|December)\s\d?\d)\]\](?:th|st|nd|rd)", "[[$1]]");
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[(\d?\d)(?:th|st|nd|rd)\s(January|February|March|April|May|June|July|August|September|October|November|December)\]\]", "[[$1 $2]]");

//Month+day_number piped into number. Preferences do not work. They don't work in sequence because digits in the two dates must be adjacent
ArticleText=Regex.Replace(ArticleText, @"(?i)([^\[]{4})\[\[((?:January|February|March|April|May|June|July|August|September|October|November|December)\s\d?\d)\]\](\s?\-?\s?)\[\[(?:January|February|March|April|May|June|July|August|September|October|November|December)\s\d{1,2}(?:th|st|nd|rd)\|(\d{1,2}(?:th|st|nd|rd))\]\]", "$1$2$3$4");
//same again but with ndash or mdash instead of hyphen
ArticleText=Regex.Replace(ArticleText, @"(?i)([^\[]{4})\[\[((?:January|February|March|April|May|June|July|August|September|October|November|December)\s\d?\d)\]\](\s?&[nm]dash;\s?)\[\[(?:January|February|March|April|May|June|July|August|September|October|November|December)\s\d{1,2}(?:th|st|nd|rd)\|(\d{1,2}(?:th|st|nd|rd))\]\]", "$1$2$3$4");
//same again but with slash instead of hyphen
ArticleText=Regex.Replace(ArticleText, @"(?i)([^\[]{4})\[\[((?:January|February|March|April|May|June|July|August|September|October|November|December)\s\d?\d)\]\](\/)\[\[(?:January|February|March|April|May|June|July|August|September|October|November|December)\s\d{1,2}(?:th|st|nd|rd)\|(\d{1,2}(?:th|st|nd|rd))\]\]", "$1$2$3$4");

ArticleText=Regex.Replace(ArticleText, @"(?i)([^\[]{4})\[\[((?:January|February|March|April|May|June|July|August|September|October|November|December)\s\d?\d)\]\](\s?\-?\s?)\[\[(\d{1,2}(?:th|st|nd|rd))\]\]", "$1$2$3$4");
//same again but with ndash instead of hyphen
ArticleText=Regex.Replace(ArticleText, @"(?i)([^\[]{4})\[\[((?:January|February|March|April|May|June|July|August|September|October|November|December)\s\d?\d)\]\](\s?&[nm]dash;\s?)\[\[(\d{1,2})\]\]", "$1$2$3$4");
//same again but with slash instead of hyphen
ArticleText=Regex.Replace(ArticleText, @"(?i)([^\[]{4})\[\[((?:January|February|March|April|May|June|July|August|September|October|November|December)\s\d?\d)\]\](\/)\[\[(\d{1,2}(?:th|st|nd|rd))\]\]", "$1$2$3$4");

ArticleText=Regex.Replace(ArticleText, @"(?i)([^\[]{4})\[\[(\d?\d)\s(?:January|February|March|April|May|June|July|August|September|October|November|December)\]\](\s?\-?\s?)\[\[(?:January|February|March|April|May|June|July|August|September|October|November|December)\s\d{1,2}(?:th|st|nd|rd)\|(\d{1,2}(?:th|st|nd|rd))\]\]", "$1$2$3$4");
//same again but with ndash instead of hyphen
ArticleText=Regex.Replace(ArticleText, @"(?i)([^\[]{4})\[\[(\d?\d)\s(?:January|February|March|April|May|June|July|August|September|October|November|December)\]\](\s?&[nm]dash;\s?)\[\[(?:January|February|March|April|May|June|July|August|September|October|November|December)\s\d{1,2}(?:th|st|nd|rd)\|(\d{1,2}(?:th|st|nd|rd))\]\]", "$1$2$3$4");
//same again but with slash instead of hyphen
ArticleText=Regex.Replace(ArticleText, @"(?i)([^\[]{4})\[\[(\d?\d)\s(?:January|February|March|April|May|June|July|August|September|October|November|December)\]\](\/)\[\[(?:January|February|March|April|May|June|July|August|September|October|November|December)\s\d{1,2}(?:th|st|nd|rd)\|(\d{1,2}(?:th|st|nd|rd))\]\]", "$1$2$3$4");

ArticleText=Regex.Replace(ArticleText, @"(?i)([^\[]{4})\[\[(\d?\d)\s(?:January|February|March|April|May|June|July|August|September|October|November|December)\]\](\s?\-?\s?)\[\[(\d{1,2}(?:th|st|nd|rd))\]\]", "$1$2$3$4");
//same again but with ndash instead of hyphen
ArticleText=Regex.Replace(ArticleText, @"(?i)([^\[]{4})\[\[(\d?\d)\s(?:January|February|March|April|May|June|July|August|September|October|November|December)\]\](\s?&[nm]dash;\s?)\[\[(\d{1,2}(?:th|st|nd|rd))\]\]", "$1$2$3$4");
//same again but with slash instead of hyphen
ArticleText=Regex.Replace(ArticleText, @"(?i)([^\[]{4})\[\[(\d?\d)\s(?:January|February|March|April|May|June|July|August|September|October|November|December)\]\](\/)\[\[(\d{1,2}(?:th|st|nd|rd))\]\]", "$1$2$3$4");

ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[(?:January|February|March|April|May|June|July|August|September|October|November|December)\s\d{1,2}(?:th|st|nd|rd)\|(\d{1,2}(?:th|st|nd|rd))\]\]", "$1");
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[\d{1,2}(?:th|st|nd|rd)\s(?:January|February|March|April|May|June|July|August|September|October|November|December)\|(\d{1,2}(?:th|st|nd|rd))\]\]", "$1");

ArticleText=Regex.Replace(ArticleText, @"\[\[(?:January|February|March|April|May|June|July|August|September|October|November|December)\s\d{1,2}(?:th|st|nd|rd)\|((?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s\d{1,2}(?:th|st|nd|rd))\]\]", "$1");
//month+day piped into month+day or vice versa
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[\d{1,2}(?:th|st|nd|rd)\s(?:January|February|March|April|May|June|July|August|September|October|November|December)\|((?:January|February|March|April|May|June|July|August|September|October|November|December)\s\d{1,2}(?:th|st|nd|rd))\]\]", "$1");
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[(?:January|February|March|April|May|June|July|August|September|October|November|December)\s\d{1,2}(?:th|st|nd|rd)\|(\d{1,2}(?:th|st|nd|rd)\s(?:January|February|March|April|May|June|July|August|September|October|November|December))\]\]", "$1");

// days of the week in full. Optional plurals
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[(?:Mondays?\||)(Mondays?|Mon)\]\]", "$1");
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[(?:Tuesdays?\||)(Tuesdays?|Tues?)\]\]", "$1");
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[(?:Wednesdays?\||)(Wednesdays?|Wed)\]\]", "$1");
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[(?:Thursdays?\||)(Thursdays?|Thur?)\]\]", "$1");
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[(?:Fridays?\||)(Fridays?|Fri)\]\]", "$1");
ArticleText=Regex.Replace(ArticleText, @"\[\[(?:Saturdays?\||)(Saturdays?|Sat)\]\]", "$1");
ArticleText=Regex.Replace(ArticleText, @"\[\[(?:Sundays?\||)(Sundays?|Sun)\]\]", "$1");

//4 digit years piped into 2
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[\d{1,4}\|(\d{1,2}(?:th|st|nd|rd))\]\]", "$1");

//full dates with incorrect 'year in'
ArticleText=Regex.Replace(ArticleText, @"(?i)(\[\[(?:January|February|March|April|May|June|July|August|September|October|November|December)\s(?:[0-3][\d]|[\d])\]\]),\s\[\[(\d{1,4})\sin\s[^\]]{1,32}\]\]", "$1 $2");
ArticleText=Regex.Replace(ArticleText, @"(?i)(\[\[(?:[0-3][\d]|[\d])\s(?:January|February|March|April|May|June|July|August|September|October|November|December)\]\])\s\[\[(\d{1,4})\sin\s[^\]]{1,32}\]\]", "$1 $2");
ArticleText=Regex.Replace(ArticleText, @"(?i)(\[\[(?:[0-3][\d]|[\d])\s(?:January|February|March|April|May|June|July|August|September|October|November|December)\]\])\s{{(?:avyear|by|fy|ly|scy|sdy)\|(\d{1,4})}}", "$1 [[$2]]");
ArticleText=Regex.Replace(ArticleText, @"(?i)(\[\[(?:January|February|March|April|May|June|July|August|September|October|November|December)\s(?:[0-3][\d]|[\d])\]\]),\s{{(?:avyear|by|fy|ly|scy|sdy)\|(\d{1,4})}}", "$1 [[$2]]");

//remove leading zero from linked date
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\s0(\d)(?:th|st|nd|rd|)\]\]", "[[$1 $2]]");
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[0(\d)(?:th|st|nd|rd|)\s(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\]\]", "[[$1 $2]]");

//delink dates to dmy
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\s(\d?\d)(?:th|st|nd|rd|)\]\],?\s?\[\[(\d{1,4})\]\]", "$2 $1 $3");
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\s(\d?\d)(?:th|st|nd|rd|)\]\],?\s?(\d{1,4})([^\w\d])", "$2 $1 $3$4");
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\s(\d?\d)(?:th|st|nd|rd|)\]\]", "$2 $1");

ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[(\d?\d)(?:th|st|nd|rd|)\s(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\]\],?\s?\[\[(\d{1,4})\]\]", "$1 $2 $3");
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[(\d?\d)(?:th|st|nd|rd|)\s(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\]\],?\s?(\d{1,4})([^\w\d])", "$1 $2 $3$4");
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[(\d?\d)(?:th|st|nd|rd|)\s(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\]\]", "$1 $2");

//year: temporary change to protect accessyear. Undone below at #1
ArticleText=Regex.Replace(ArticleText, @"(?i)(accessyear\s?=\s?)\[\[(\d{1,4})\]\]", "$1xx$2xx");
//year: now remove unprotected linked years
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[(\d{1,4})\]\]", "$1");
//year: #1. Undo temporary change to protect accessyear and date preference dates
ArticleText=Regex.Replace(ArticleText, @"(?i)xx(\d{1,4})xx", "[[$1]]");

//remove dts-simple template that links dates
ArticleText=Regex.Replace(ArticleText, @"(?i){{dts-simple\|(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\|\s?(\d\d?)\|(\d{1,4})}}", "$2 $1 $3");

//remove dts3 template that links dates
ArticleText=Regex.Replace(ArticleText, @"(?i){{dts3\|(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\|(\d\d?)\|(\d{1,4})}}", "$2 $1 $3");

//change deprecated dts2 template
ArticleText=Regex.Replace(ArticleText, @"(?i){{dts2\|(.*?)\|(.*?)\|(.*?)}}", "{{dts|link=off|format=dmy|$3|$2|$1}}");
//fix dts template
ArticleText=Regex.Replace(ArticleText, @"(?i)({{dts\|)", "$1link=off|format=dmy|");
ArticleText=Regex.Replace(ArticleText, @"(?i)({{dts\|)link=off\|([^}]*link=off)", "$1$2");
ArticleText=Regex.Replace(ArticleText, @"(?i)({{dts\|)format=dmy\|([^}]*format=dmy)", "$1$2");

//change deprecated birth and death templates
ArticleText=Regex.Replace(ArticleText, @"(?i)({{(?:Birth|Death|release)[^}]*)\|mf=ye?s?", "$1");
ArticleText=Regex.Replace(ArticleText, @"(?i)({{(?:Birth|Death|release)[^|]*\|)", "$1df=yes|");
ArticleText=Regex.Replace(ArticleText, @"(?i)({{(?:Birth|Death|release)[^|]*\|)df=ye?s?\|([^}]*df=ye?s?)", "$1$2");

//remove leading zero from nonlinked date
ArticleText=Regex.Replace(ArticleText, @"(?i)([^\d][^\w\d])(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\s0(\d)(?:th|st|nd|rd|)([^\w\d][^\d])", "$1$2 $3$4");
ArticleText=Regex.Replace(ArticleText, @"(?i)([^\d][^\w\d])0(\d)(?:th|st|nd|rd|)\s(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)([^\w\d][^\d])", "$1$2 $3$4");

//all dates to dmy
ArticleText=Regex.Replace(ArticleText, @"(?i)([^\d][^\w\d])(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\s([0-3]?\d)(?:th|st|nd|rd|),?\s(\d{1,4})([^\w\d][^\d])", "$1$3 $2 $4$5");
ArticleText=Regex.Replace(ArticleText, @"(?i)([^\d][^\w\d])(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\s([0-3]?\d)(?:th|st|nd|rd|)([^\w\d][^\d])", "$1$3 $2$4");

//Month+day_number "March 7th" -> "March 7"
ArticleText=Regex.Replace(ArticleText, @"(?i)([^\d][^\w\d])([0-3]?\d)(?:th|st|nd|rd|)\s(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)([^\w\d][^\d])", "$1$2 $3$4");

//year: temporary change to protect accessyear. Undone below at #1
ArticleText=Regex.Replace(ArticleText, @"(?i)(accessyear\s?=\s?)\[\[(\d{1,4})\]\]", "$1xx$2xx");
//year: now remove unprotected linked years
ArticleText=Regex.Replace(ArticleText, @"(?i)\[\[(\d{1,4})\]\]", "$1");
//year: #1. Undo temporary change to protect accessyear and date preference dates
ArticleText=Regex.Replace(ArticleText, @"(?i)xx(\d{1,4})xx", "[[$1]]");

//unprotect certain dates   

ArticleText=Regex.Replace(ArticleText, @"(?i)[♫]", "");

return ht.AddBack(ArticleText);

return ArticleText;
}
//