User:Ohconfucius/script/MOSNUM dates.js: Difference between revisions

Content deleted Content added
tweak tag and date insertion
fully protect archive-url with built-in spacces
 
(484 intermediate revisions by 6 users not shown)
Line 1:
//NOTE TO SELF: Date parameters in {{dmy/mdy}} template need updating at the start of each month
 
// This script aligns dates into one of two formats allowed by [[WP:MOSNUM]].
// PLEASE READ THE DOCUMENTATION at [[User:Ohconfucius/script/MOSNUM dates]] (click on the link above) before using.
 
// Feedback and constructive criticism are welcome
 
// <pre>
function Ohc_unambiguous_dates(){
$.when(
var txt=document.editform.wpTextbox1;
$.ajax("//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js", { dataType: "script", cache: true }),
// resolvable ambiguous date formats
$.ajax("//en.wikipedia.org/w/index.php?title=User:Ohconfucius/script/MOSNUM_utils.js&action=raw&ctype=text/javascript", { dataType: "script", cache: true })
//4-digit year universal
).then(function() {
txt.value=txt.value.replace(/([^\d])\s0?1\/0?1\/(\d{4})(?![\w\d-])/g, '$1 1 January $2');
pathoschild.TemplateScript.add(
txt.value=txt.value.replace(/([^\d])\s0?2\/0?2\/(\d{4})(?![\w\d-])/g, '$1 2 February $2');
[
txt.value=txt.value.replace(/([^\d])\s0?3\/0?3\/(\d{4})(?![\w\d-])/g, '$1 3 March $2');
{
txt.value=txt.value.replace(/([^\d])\s0?4\/0?4\/(\d{4})(?![\w\d-])/g, '$1 4 April $2');
name: "DATES to dmy",
txt.value=txt.value.replace(/([^\d])\s0?5\/0?5\/(\d{4})(?![\w\d-])/g, '$1 5 May $2');
tooltip: "Align all dates to dmy",
txt.value=txt.value.replace(/([^\d])\s0?6\/0?6\/(\d{4})(?![\w\d-])/g, '$1 6 June $2');
script: ohc_all_to_dmy_driver
txt.value=txt.value.replace(/([^\d])\s0?7\/0?7\/(\d{4})(?![\w\d-])/g, '$1 7 July $2');
},
txt.value=txt.value.replace(/([^\d])\s0?8\/0?8\/(\d{4})(?![\w\d-])/g, '$1 8 August $2');
{
txt.value=txt.value.replace(/([^\d])\s0?9\/0?9\/(\d{4})(?![\w\d-])/g, '$1 9 September $2');
name: "DATES to mdy",
txt.value=txt.value.replace(/([^\d])\s10\/10\/(\d{4})(?![\w\d-])/g, '$1 10 October $2');
tooltip: "Align all dates to mdy",
txt.value=txt.value.replace(/([^\d])\s11\/11\/(\d{4})(?![\w\d-])/g, '$1 11 November $2');
script: ohc_all_to_mdy_driver
txt.value=txt.value.replace(/([^\d])\s12\/12\/(\d{4})(?![\w\d-])/g, '$1 12 December $2');
},
{
name: "DMY_cs1=ly",
tooltip: "Access & archive dates",
script: ohc_dmy_cs1_ly_driver
},
{
name: "MDY_cs1=ly",
tooltip: "say hello",
script: ohc_mdy_cs1_ly_driver
},
{
name: "US-slash dates",
tooltip: "US-slash",
script: ohc_US_slash_dates_driver
},
{
name: "UK-slash dates",
tooltip: "UK-slash",
script: ohc_UK_slash_dates_driver
}
],
 
// common options
//4-digit year UK style
{ forActions: "edit", category: "MOSNUM Dates" }
txt.value=txt.value.replace(/([^\w\d-][23]\d)\/0?1\/(\d{4})(?![\w\d-])/g, '$1 January $2');
);
txt.value=txt.value.replace(/([^\w\d-][23]\d)\/0?2\/(\d{4})(?![\w\d-])/g, '$1 February $2');
});
txt.value=txt.value.replace(/([^\w\d-][23]\d)\/0?3\/(\d{4})(?![\w\d-])/g, '$1 March $2');
txt.value=txt.value.replace(/([^\w\d-][23]\d)\/0?4\/(\d{4})(?![\w\d-])/g, '$1 April $2');
txt.value=txt.value.replace(/([^\w\d-][23]\d)\/0?5\/(\d{4})(?![\w\d-])/g, '$1 May $2');
txt.value=txt.value.replace(/([^\w\d-][23]\d)\/0?6\/(\d{4})(?![\w\d-])/g, '$1 June $2');
txt.value=txt.value.replace(/([^\w\d-][23]\d)\/0?7\/(\d{4})(?![\w\d-])/g, '$1 July $2');
txt.value=txt.value.replace(/([^\w\d-][23]\d)\/0?8\/(\d{4})(?![\w\d-])/g, '$1 August $2');
txt.value=txt.value.replace(/([^\w\d-][23]\d)\/0?9\/(\d{4})(?![\w\d-])/g, '$1 September $2');
txt.value=txt.value.replace(/([^\w\d-][23]\d)\/10\/(\d{4})(?![\w\d-])/g, '$1 October $2');
txt.value=txt.value.replace(/([^\w\d-][23]\d)\/11\/(\d{4})(?![\w\d-])/g, '$1 November $2');
txt.value=txt.value.replace(/([^\w\d-][23]\d)\/12\/(\d{4})(?![\w\d-])/g, '$1 December $2');
txt.value=txt.value.replace(/([^\w\d-]1[3-9])\/0?1\/(\d{4})(?![\w\d-])/g, '$1 January $2');
txt.value=txt.value.replace(/([^\w\d-]1[3-9])\/0?2\/(\d{4})(?![\w\d-])/g, '$1 February $2');
txt.value=txt.value.replace(/([^\w\d-]1[3-9])\/0?3\/(\d{4})(?![\w\d-])/g, '$1 March $2');
txt.value=txt.value.replace(/([^\w\d-]1[3-9])\/0?4\/(\d{4})(?![\w\d-])/g, '$1 April $2');
txt.value=txt.value.replace(/([^\w\d-]1[3-9])\/0?5\/(\d{4})(?![\w\d-])/g, '$1 May $2');
txt.value=txt.value.replace(/([^\w\d-]1[3-9])\/0?6\/(\d{4})(?![\w\d-])/g, '$1 June $2');
txt.value=txt.value.replace(/([^\w\d-]1[3-9])\/0?7\/(\d{4})(?![\w\d-])/g, '$1 July $2');
txt.value=txt.value.replace(/([^\w\d-]1[3-9])\/0?8\/(\d{4})(?![\w\d-])/g, '$1 August $2');
txt.value=txt.value.replace(/([^\w\d-]1[3-9])\/0?9\/(\d{4})(?![\w\d-])/g, '$1 September $2');
txt.value=txt.value.replace(/([^\w\d-]1[3-9])\/10\/(\d{4})(?![\w\d-])/g, '$1 October $2');
txt.value=txt.value.replace(/([^\w\d-]1[3-9])\/11\/(\d{4})(?![\w\d-])/g, '$1 November $2');
txt.value=txt.value.replace(/([^\w\d-]1[3-9])\/12\/(\d{4})(?![\w\d-])/g, '$1 December $2');
 
/**
//4-digit year US style
* Add custom extension methods to the TemplateScript editor.
txt.value=txt.value.replace(/([^\w\d-])0?1\/([23]\d)\/(\d{4})(?![\w\d-])/g, '$1 January $2, $3');
* @param editor The TemplateScript editor to extend.
txt.value=txt.value.replace(/([^\w\d-])0?2\/([23]\d)\/(\d{4})(?![\w\d-])/g, '$1 February $2, $3');
*/
txt.value=txt.value.replace(/([^\w\d-])0?3\/([23]\d)\/(\d{4})(?![\w\d-])/g, '$1 March $2, $3');
function ohc_extend_editor(editor) {
txt.value=txt.value.replace(/([^\w\d-])0?4\/([23]\d)\/(\d{4})(?![\w\d-])/g, '$1 April $2, $3');
editor.ohc_regex = function(rg, sub, func) {
txt.value=txt.value.replace(/([^\w\d-])0?5\/([23]\d)\/(\d{4})(?![\w\d-])/g, '$1 May $2, $3');
var text = editor.get();
txt.value=txt.value.replace(/([^\w\d-])0?6\/([23]\d)\/(\d{4})(?![\w\d-])/g, '$1 June $2, $3');
text = ohc.dateutil.regex(text, rg, sub, func);
txt.value=txt.value.replace(/([^\w\d-])0?7\/([23]\d)\/(\d{4})(?![\w\d-])/g, '$1 July $2, $3');
editor.set(text);
txt.value=txt.value.replace(/([^\w\d-])0?8\/([23]\d)\/(\d{4})(?![\w\d-])/g, '$1 August $2, $3');
txt.value=txt.value.replace(/([^\w\d-])0?9\/([23]\d)\/(\d{4})(?![\w\d-])/g, '$1 September $2, $3');
txt.value=txt.value.replace(/([^\w\d-])10\/([23]\d)\/(\d{4})(?![\w\d-])/g, '$1 October $2, $3');
txt.value=txt.value.replace(/([^\w\d-])11\/([23]\d)\/(\d{4})(?![\w\d-])/g, '$1 November $2, $3');
txt.value=txt.value.replace(/([^\w\d-])12\/([23]\d)\/(\d{4})(?![\w\d-])/g, '$1 December $2, $3');
txt.value=txt.value.replace(/([^\w\d-])0?1\/(1[3-9])\/(\d{4})(?![\w\d-])/g, '$1 January $2,\'$3');
txt.value=txt.value.replace(/([^\w\d-])0?2\/(1[3-9])\/(\d{4})(?![\w\d-])/g, '$1 February $2, $3');
txt.value=txt.value.replace(/([^\w\d-])0?3\/(1[3-9])\/(\d{4})(?![\w\d-])/g, '$1 March $2, $3');
txt.value=txt.value.replace(/([^\w\d-])0?4\/(1[3-9])\/(\d{4})(?![\w\d-])/g, '$1 April $2, $3');
txt.value=txt.value.replace(/([^\w\d-])0?5\/(1[3-9])\/(\d{4})(?![\w\d-])/g, '$1 May $2, $3');
txt.value=txt.value.replace(/([^\w\d-])0?6\/(1[3-9])\/(\d{4})(?![\w\d-])/g, '$1 June $2, $3');
txt.value=txt.value.replace(/([^\w\d-])0?7\/(1[3-9])\/(\d{4})(?![\w\d-])/g, '$1 July $2, $3');
txt.value=txt.value.replace(/([^\w\d-])0?8\/(1[3-9])\/(\d{4})(?![\w\d-])/g, '$1 August $2, $3');
txt.value=txt.value.replace(/([^\w\d-])0?9\/(1[3-9])\/(\d{4})(?![\w\d-])/g, '$1 September $2, $3');
txt.value=txt.value.replace(/([^\w\d-])10\/(1[3-9])\/(\d{4})(?![\w\d-])/g, '$1 October $2, $3');
txt.value=txt.value.replace(/([^\w\d-])11\/(1[3-9])\/(\d{4})(?![\w\d-])/g, '$1 November $2, $3');
txt.value=txt.value.replace(/([^\w\d-])12\/(1[3-9])\/(\d{4})(?![\w\d-])/g, '$1 December $2, $3');
 
return editor;
//2-digit year ('00-'19) universal
};
txt.value=txt.value.replace(/([^\d])\s0?1\/0?1\/([01]\d)(?![\w\d-])/g, '$1 1 January 20$2');
}
txt.value=txt.value.replace(/([^\d])\s0?2\/0?2\/([01]\d)(?![\w\d-])/g, '$1 2 February 20$2');
txt.value=txt.value.replace(/([^\d])\s0?3\/0?3\/([01]\d)(?![\w\d-])/g, '$1 3 March 20$2');
txt.value=txt.value.replace(/([^\d])\s0?4\/0?4\/([01]\d)(?![\w\d-])/g, '$1 4 April 20$2');
txt.value=txt.value.replace(/([^\d])\s0?5\/0?5\/([01]\d)(?![\w\d-])/g, '$1 5 May 20$2');
txt.value=txt.value.replace(/([^\d])\s0?6\/0?6\/([01]\d)(?![\w\d-])/g, '$1 6 June 20$2');
txt.value=txt.value.replace(/([^\d])\s0?7\/0?7\/([01]\d)(?![\w\d-])/g, '$1 7 July 20$2');
txt.value=txt.value.replace(/([^\d])\s0?8\/0?8\/([01]\d)(?![\w\d-])/g, '$1 8 August 20$2');
txt.value=txt.value.replace(/([^\d])\s0?9\/0?9\/([01]\d)(?![\w\d-])/g, '$1 9 September 20$2');
txt.value=txt.value.replace(/([^\d])\s10\/10\/([01]\d)(?![\w\d-])/g, '$1 10 October 20$2');
txt.value=txt.value.replace(/([^\d])\s11\/11\/([01]\d)(?![\w\d-])/g, '$1 11 November 20$2');
txt.value=txt.value.replace(/([^\d])\s12\/12\/([01]\d)(?![\w\d-])/g, '$1 12 December 20$2');
 
function ohc_fix_unambiguous_dates(editor) {
//2-digit year ('00-'19) UK style
editor
txt.value=txt.value.replace(/([^\w\d-][23]\d)\/0?1\/([01]\d)(?![\w\d-])/g, '$1 January 20$2');
// resolvable ambiguous date formats
txt.value=txt.value.replace(/([^\w\d-][23]\d)\/0?2\/([01]\d)(?![\w\d-])/g, '$1 February 20$2');
// UK style
txt.value=txt.value.replace(/([^\w\d-][23]\d)\/0?3\/([01]\d)(?![\w\d-])/g, '$1 March 20$2');
txt .value=txt.value.replaceohc_regex(/([^-\w/:\d-.][23]\d)@DD\/0?4.@MM\/([01]\d).@YYYY(?!=[^-–/\w\d-&])/ggi, '"$1@Day April@Month 20$2'@YYYY", function(d); {
if (d.d == d.m) return true;
txt.value=txt.value.replace(/([^\w\d-][23]\d)\/0?5\/([01]\d)(?![\w\d-])/g, '$1 May 20$2');
if (d.d > 12) return true;
txt.value=txt.value.replace(/([^\w\d-][23]\d)\/0?6\/([01]\d)(?![\w\d-])/g, '$1 June 20$2');
return false;
txt.value=txt.value.replace(/([^\w\d-][23]\d)\/0?7\/([01]\d)(?![\w\d-])/g, '$1 July 20$2');
})
txt.value=txt.value.replace(/([^\w\d-][23]\d)\/0?8\/([01]\d)(?![\w\d-])/g, '$1 August 20$2');
txt .value=txt.value.replaceohc_regex(/([^-\w/:\d-.][23]\d)@DD\/0?9@MM\/([01]\d)@YYYY(?!=[^-–/\w\d-&])/ggi, '"$1@Day September@Month 20$2'@YYYY", function(d); {
if (d.d == d.m) return true;
txt.value=txt.value.replace(/([^\w\d-][23]\d)\/10\/([01]\d)(?![\w\d-])/g, '$1 October 20$2');
if (d.d > 12) return true;
txt.value=txt.value.replace(/([^\w\d-][23]\d)\/11\/([01]\d)(?![\w\d-])/g, '$1 November 20$2');
return false;
txt.value=txt.value.replace(/([^\w\d-][23]\d)\/12\/([01]\d)(?![\w\d-])/g, '$1 December 20$2');
})
txt.value=txt.value.replace(/([^\w\d-]1[3-9])\/0?1\/([01]\d)(?![\w\d-])/g, '$1 January 20$2');
txt.value=txt.value.replace(/([^\w\d-]1[3-9])\/0?2\/([01]\d)(?![\w\d-])/g, '$1 February 20$2');
txt.value=txt.value.replace(/([^\w\d-]1[3-9])\/0?3\/([01]\d)(?![\w\d-])/g, '$1 March 20$2');
txt.value=txt.value.replace(/([^\w\d-]1[3-9])\/0?4\/([01]\d)(?![\w\d-])/g, '$1 April 20$2');
txt.value=txt.value.replace(/([^\w\d-]1[3-9])\/0?5\/([01]\d)(?![\w\d-])/g, '$1 May 20$2');
txt.value=txt.value.replace(/([^\w\d-]1[3-9])\/0?6\/([01]\d)(?![\w\d-])/g, '$1 June 20$2');
txt.value=txt.value.replace(/([^\w\d-]1[3-9])\/0?7\/([01]\d)(?![\w\d-])/g, '$1 July 20$2');
txt.value=txt.value.replace(/([^\w\d-]1[3-9])\/0?8\/([01]\d)(?![\w\d-])/g, '$1 August 20$2');
txt.value=txt.value.replace(/([^\w\d-]1[3-9])\/0?9\/([01]\d)(?![\w\d-])/g, '$1 September 20$2');
txt.value=txt.value.replace(/([^\w\d-]1[3-9])\/10\/([01]\d)(?![\w\d-])/g, '$1 October 20$2');
txt.value=txt.value.replace(/([^\w\d-]1[3-9])\/11\/([01]\d)(?![\w\d-])/g, '$1 November 20$2');
txt.value=txt.value.replace(/([^\w\d-]1[3-9])\/12\/([01]\d)(?![\w\d-])/g, '$1 December 20$2');
 
//2-digit year ('00-'19) US style
txt .value=txt.value.replaceohc_regex(/([^-\w/:\d-.])0?1@MM\/([23].@DD\d)\/([01]\d).@YYYY(?!=[^-–/\w\d-&])/ggi, '"$1@Month January@Day, $2@YYYY", 20$3'function(d); {
if (d.d > 12) return true;
txt.value=txt.value.replace(/([^\w\d-])0?2\/([23]\d)\/([01]\d)(?![\w\d-])/g, '$1 February $2, 20$3');
return false;
txt.value=txt.value.replace(/([^\w\d-])0?3\/([23]\d)\/([01]\d)(?![\w\d-])/g, '$1 March $2, 20$3');
})
txt.value=txt.value.replace(/([^\w\d-])0?4\/([23]\d)\/([01]\d)(?![\w\d-])/g, '$1 April $2, 20$3');
txt .value=txt.value.replaceohc_regex(/([^-\w/:\d-.])0?5@MM\/([23]\d)@DD\/([01]\d)@YYYY(?!=[^-–/\w\d-&])/ggi, '"$1@Month May@Day, $2@YYYY", 20$3'function(d); {
if (d.d > 12) return true;
txt.value=txt.value.replace(/([^\w\d-])0?6\/([23]\d)\/([01]\d)(?![\w\d-])/g, '$1 June $2, 20$3');
return false;
txt.value=txt.value.replace(/([^\w\d-])0?7\/([23]\d)\/([01]\d)(?![\w\d-])/g, '$1 July $2, 20$3');
});
txt.value=txt.value.replace(/([^\w\d-])0?8\/([23]\d)\/([01]\d)(?![\w\d-])/g, '$1 August $2, 20$3');
}
txt.value=txt.value.replace(/([^\w\d-])0?9\/([23]\d)\/([01]\d)(?![\w\d-])/g, '$1 September $2, 20$3');
txt.value=txt.value.replace(/([^\w\d-])10\/([23]\d)\/([01]\d)(?![\w\d-])/g, '$1 October $2, 20$3');
txt.value=txt.value.replace(/([^\w\d-])11\/([23]\d)\/([01]\d)(?![\w\d-])/g, '$1 November $2, 20$3');
txt.value=txt.value.replace(/([^\w\d-])12\/([23]\d)\/([01]\d)(?![\w\d-])/g, '$1 December $2, 20$3');
txt.value=txt.value.replace(/([^\w\d-])0?1\/(1[3-9])\/([01]\d)(?![\w\d-])/g, '$1 January $2,20$3');
txt.value=txt.value.replace(/([^\w\d-])0?2\/(1[3-9])\/([01]\d)(?![\w\d-])/g, '$1 February $2, 20$3');
txt.value=txt.value.replace(/([^\w\d-])0?3\/(1[3-9])\/([01]\d)(?![\w\d-])/g, '$1 March $2, 20$3');
txt.value=txt.value.replace(/([^\w\d-])0?4\/(1[3-9])\/([01]\d)(?![\w\d-])/g, '$1 April $2, 20$3');
txt.value=txt.value.replace(/([^\w\d-])0?5\/(1[3-9])\/([01]\d)(?![\w\d-])/g, '$1 May $2, 20$3');
txt.value=txt.value.replace(/([^\w\d-])0?6\/(1[3-9])\/([01]\d)(?![\w\d-])/g, '$1 June $2, 20$3');
txt.value=txt.value.replace(/([^\w\d-])0?7\/(1[3-9])\/([01]\d)(?![\w\d-])/g, '$1 July $2, 20$3');
txt.value=txt.value.replace(/([^\w\d-])0?8\/(1[3-9])\/([01]\d)(?![\w\d-])/g, '$1 August $2, 20$3');
txt.value=txt.value.replace(/([^\w\d-])0?9\/(1[3-9])\/([01]\d)(?![\w\d-])/g, '$1 September $2, 20$3');
txt.value=txt.value.replace(/([^\w\d-])10\/(1[3-9])\/([01]\d)(?![\w\d-])/g, '$1 October $2, 20$3');
txt.value=txt.value.replace(/([^\w\d-])11\/(1[3-9])\/([01]\d)(?![\w\d-])/g, '$1 November $2, 20$3');
txt.value=txt.value.replace(/([^\w\d-])12\/(1[3-9])\/([01]\d)(?![\w\d-])/g, '$1 December $2, 20$3');
 
function ohc_US_slash_dates_to_mdy(editor) {
//2-digit year ('60-'99) universal
editor
txt.value=txt.value.replace(/([^\d])\s0?1\/0?1\/([6-9]\d)(?![\w\d-])/g, '$1 1 January 19$2');
// ranges
txt.value=txt.value.replace(/([^\d])\s0?2\/0?2\/([6-9]\d)(?![\w\d-])/g, '$1 2 February 19$2');
.ohc_regex(/([^-\d/:\.])@MM\/@DD\/@YYNN(&nbsp;|\s)?(?:(?:[-–—]|&[mn]dash;)(?:&nbsp;|\s)?)@MM\/@DD\/@YYNN(?=[^-–/\w&])/gi, "$1@Mon1 @Day1, @Year1$2 – @Mon2 @Day2, @Year2")
txt.value=txt.value.replace(/([^\d])\s0?3\/0?3\/([6-9]\d)(?![\w\d-])/g, '$1 3 March 19$2');
.ohc_regex(/([^-\d/:\.])@MM\.@DD\.@YYNN(&nbsp;|\s)?(?:(?:[-–—]|&[mn]dash;)(?:&nbsp;|\s)?)@MM\.@DD\.@YYNN(?=[^-–/\w&])/gi, "$1@Mon1 @Day1, @Year1$2 – @Mon2 @Day2, @Year2")
txt.value=txt.value.replace(/([^\d])\s0?4\/0?4\/([6-9]\d)(?![\w\d-])/g, '$1 4 April 19$2');
.ohc_regex(/(\| ?)@MM\/@DD\/@YYNN(&nbsp;|\s)?(?:(?:[-–—]|&[mn]dash;)(?:&nbsp;|\s)?)@MM\/@DD\/@YYNN(?=\s*\|)/gi, "$1@Mon1 @Day1, @Year1$2 – @Mon2 @Day2, @Year2")
txt.value=txt.value.replace(/([^\d])\s0?5\/0?5\/([6-9]\d)(?![\w\d-])/g, '$1 5 May 19$2');
.ohc_regex(/(\| ?)@MM\.@DD\.@YYNN(&nbsp;|\s)?(?:(?:[-–—]|&[mn]dash;)(?:&nbsp;|\s)?)@MM\.@DD\.@YYNN(?=\s*\|)/gi, "$1@Mon1 @Day1, @Year1$2 – @Mon @Day2, @Year2")
txt.value=txt.value.replace(/([^\d])\s0?6\/0?6\/([6-9]\d)(?![\w\d-])/g, '$1 6 June 19$2');
txt.value=txt.value.replace(/([^\d])\s0?7\/0?7\/([6-9]\d)(?![\w\d-])/g, '$1 7 July 19$2');
txt.value=txt.value.replace(/([^\d])\s0?8\/0?8\/([6-9]\d)(?![\w\d-])/g, '$1 8 August 19$2');
txt.value=txt.value.replace(/([^\d])\s0?9\/0?9\/([6-9]\d)(?![\w\d-])/g, '$1 9 September 19$2');
txt.value=txt.value.replace(/([^\d])\s10\/10\/([6-9]\d)(?![\w\d-])/g, '$1 10 October 19$2');
txt.value=txt.value.replace(/([^\d])\s11\/11\/([6-9]\d)(?![\w\d-])/g, '$1 11 November 19$2');
txt.value=txt.value.replace(/([^\d])\s12\/12\/([6-9]\d)(?![\w\d-])/g, '$1 12 December 19$2');
 
// resolvable ambiguous date formats
//2-digit year ('60-'99) UK style
txt .value=txt.value.replaceohc_regex(/([^-\wd/:\d-.][23]\d)@MM\/0?1@DD\/@YYNN(?=[6^-9]\d)(?![–/\w\d-&])/ggi, '"$1@Month January@Day, 19$2'@YYYY");
txt .value=txt.value.replaceohc_regex(/([^\w\d-][23]\d)\/0?2:\/([6-9.])@MM\d).@DD\.@YYNN(?!=[^-–/\w\d-&])/ggi, '"$1@Month February@Day, 19$2'@YYYY");
txt .value=txt.value.replaceohc_regex(/([^\w\d-][23]\d)\/0?3:\/(.])@MM[6-9]\d)@DD[-–]@YYNN(?!=[^-–/\w\d-&])/ggi, '"$1@Month March@Day, 19$2'@YYYY");
txt .value=txt.value.replaceohc_regex(/([^\w\d-][23]\d| ?)@MM\/0?4@DD\/([6-9]\d)@YYNN(?![=\ws*\d-]|)/ggi, '"$1@Month April@Day, 19$2'@YYYY");
txt .value=txt.value.replaceohc_regex(/([^\w\d-][23]\d| ?)@MM\/0?5.@DD\/([6-9]\d).@YYNN(?![=\ws*\d-]|)/ggi, '"$1@Month May@Day, 19$2'@YYYY");
//.ohc_regex(/(\| ?)@MM[-–]@DD[-–]@YYNN(?=\s*\|)/gi, "$1@Month @Day, @YYYY");
txt.value=txt.value.replace(/([^\w\d-][23]\d)\/0?6\/([6-9]\d)(?![\w\d-])/g, '$1 June 19$2');
}
txt.value=txt.value.replace(/([^\w\d-][23]\d)\/0?7\/([6-9]\d)(?![\w\d-])/g, '$1 July 19$2');
txt.value=txt.value.replace(/([^\w\d-][23]\d)\/0?8\/([6-9]\d)(?![\w\d-])/g, '$1 August 19$2');
txt.value=txt.value.replace(/([^\w\d-][23]\d)\/0?9\/([6-9]\d)(?![\w\d-])/g, '$1 September 19$2');
txt.value=txt.value.replace(/([^\w\d-][23]\d)\/10\/([6-9]\d)(?![\w\d-])/g, '$1 October 19$2');
txt.value=txt.value.replace(/([^\w\d-][23]\d)\/11\/([6-9]\d)(?![\w\d-])/g, '$1 November 19$2');
txt.value=txt.value.replace(/([^\w\d-][23]\d)\/12\/([6-9]\d)(?![\w\d-])/g, '$1 December 19$2');
txt.value=txt.value.replace(/([^\w\d-]1[3-9])\/0?1\/([6-9]\d)(?![\w\d-])/g, '$1 January 19$2');
txt.value=txt.value.replace(/([^\w\d-]1[3-9])\/0?2\/([6-9]\d)(?![\w\d-])/g, '$1 February 19$2');
txt.value=txt.value.replace(/([^\w\d-]1[3-9])\/0?3\/([6-9]\d)(?![\w\d-])/g, '$1 March 19$2');
txt.value=txt.value.replace(/([^\w\d-]1[3-9])\/0?4\/([6-9]\d)(?![\w\d-])/g, '$1 April 19$2');
txt.value=txt.value.replace(/([^\w\d-]1[3-9])\/0?5\/([6-9]\d)(?![\w\d-])/g, '$1 May 19$2');
txt.value=txt.value.replace(/([^\w\d-]1[3-9])\/0?6\/([6-9]\d)(?![\w\d-])/g, '$1 June 19$2');
txt.value=txt.value.replace(/([^\w\d-]1[3-9])\/0?7\/([6-9]\d)(?![\w\d-])/g, '$1 July 19$2');
txt.value=txt.value.replace(/([^\w\d-]1[3-9])\/0?8\/([6-9]\d)(?![\w\d-])/g, '$1 August 19$2');
txt.value=txt.value.replace(/([^\w\d-]1[3-9])\/0?9\/([6-9]\d)(?![\w\d-])/g, '$1 September 19$2');
txt.value=txt.value.replace(/([^\w\d-]1[3-9])\/10\/([6-9]\d)(?![\w\d-])/g, '$1 October 19$2');
txt.value=txt.value.replace(/([^\w\d-]1[3-9])\/11\/([6-9]\d)(?![\w\d-])/g, '$1 November 19$2');
txt.value=txt.value.replace(/([^\w\d-]1[3-9])\/12\/([6-9]\d)(?![\w\d-])/g, '$1 December 19$2');
 
function ohc_UK_slash_dates_to_dmy(editor) {
//2-digit year ('60-'99) US style
editor
txt.value=txt.value.replace(/([^\w\d-])0?1\/([23]\d)\/([6-9]\d)(?![\w\d-])/g, '$1 January $2, 19$3');
// ranges
txt.value=txt.value.replace(/([^\w\d-])0?2\/([23]\d)\/([6-9]\d)(?![\w\d-])/g, '$1 February $2, 19$3');
.ohc_regex(/([^-\d/:\.])@DD\/@MM\/@YYNN(&nbsp;|\s)?(?:(?:[-–—]|&[mn]dash;)(?:&nbsp;|\s)?)@DD\/@MM\/@YYNN(?=[^-–/\w&])/gi, "$1@Day1 @Mon1 @Year1$2 – @Day2 @Mon2 @Year2")
txt.value=txt.value.replace(/([^\w\d-])0?3\/([23]\d)\/([6-9]\d)(?![\w\d-])/g, '$1 March $2, 19$3');
.ohc_regex(/([^-\d/:\.])@DD\.@MM\.@YYNN(&nbsp;|\s)?(?:(?:[-–—]|&[mn]dash;)(?:&nbsp;|\s)?)@DD\.@MM\.@YYNN(?=[^-–/\w&])/gi, "$1@Day1 @Mon1 @Year1$2 – @Day2 @Mon2 @Year2")
txt.value=txt.value.replace(/([^\w\d-])0?4\/([23]\d)\/([6-9]\d)(?![\w\d-])/g, '$1 April $2, 19$3');
.ohc_regex(/(\| ?)@DD\/@MM\/@YYNN(&nbsp;|\s)?(?:(?:[-–—]|&[mn]dash;)(?:&nbsp;|\s)?)@DD\/@MM\/@YYNN(?=\s*\|)/gi, "$1@Day1 @Mon1 @Year1$2 – @Day2 @Mon2 @Year2")
txt.value=txt.value.replace(/([^\w\d-])0?5\/([23]\d)\/([6-9]\d)(?![\w\d-])/g, '$1 May $2, 19$3');
.ohc_regex(/(\| ?)@DD\.@MM\.@YYNN(&nbsp;|\s)?(?:(?:[-–—]|&[mn]dash;)(?:&nbsp;|\s)?)@DD\.@MM\.@YYNN(?=\s*\|)/gi, "$1@Day1 @Mon1 @Year1$2 – @Day2 @Mon2 @Year2")
txt.value=txt.value.replace(/([^\w\d-])0?6\/([23]\d)\/([6-9]\d)(?![\w\d-])/g, '$1 June $2, 19$3');
txt.value=txt.value.replace(/([^\w\d-])0?7\/([23]\d)\/([6-9]\d)(?![\w\d-])/g, '$1 July $2, 19$3');
txt.value=txt.value.replace(/([^\w\d-])0?8\/([23]\d)\/([6-9]\d)(?![\w\d-])/g, '$1 August $2, 19$3');
txt.value=txt.value.replace(/([^\w\d-])0?9\/([23]\d)\/([6-9]\d)(?![\w\d-])/g, '$1 September $2, 19$3');
txt.value=txt.value.replace(/([^\w\d-])10\/([23]\d)\/([6-9]\d)(?![\w\d-])/g, '$1 October $2, 19$3');
txt.value=txt.value.replace(/([^\w\d-])11\/([23]\d)\/([6-9]\d)(?![\w\d-])/g, '$1 November $2, 19$3');
txt.value=txt.value.replace(/([^\w\d-])12\/([23]\d)\/([6-9]\d)(?![\w\d-])/g, '$1 December $2, 19$3');
txt.value=txt.value.replace(/([^\w\d-])0?1\/(1[3-9])\/([6-9]\d)(?![\w\d-])/g, '$1 January $2,19$3');
txt.value=txt.value.replace(/([^\w\d-])0?2\/(1[3-9])\/([6-9]\d)(?![\w\d-])/g, '$1 February $2, 19$3');
txt.value=txt.value.replace(/([^\w\d-])0?3\/(1[3-9])\/([6-9]\d)(?![\w\d-])/g, '$1 March $2, 19$3');
txt.value=txt.value.replace(/([^\w\d-])0?4\/(1[3-9])\/([6-9]\d)(?![\w\d-])/g, '$1 April $2, 19$3');
txt.value=txt.value.replace(/([^\w\d-])0?5\/(1[3-9])\/([6-9]\d)(?![\w\d-])/g, '$1 May $2, 19$3');
txt.value=txt.value.replace(/([^\w\d-])0?6\/(1[3-9])\/([6-9]\d)(?![\w\d-])/g, '$1 June $2, 19$3');
txt.value=txt.value.replace(/([^\w\d-])0?7\/(1[3-9])\/([6-9]\d)(?![\w\d-])/g, '$1 July $2, 19$3');
txt.value=txt.value.replace(/([^\w\d-])0?8\/(1[3-9])\/([6-9]\d)(?![\w\d-])/g, '$1 August $2, 19$3');
txt.value=txt.value.replace(/([^\w\d-])0?9\/(1[3-9])\/([6-9]\d)(?![\w\d-])/g, '$1 September $2, 19$3');
txt.value=txt.value.replace(/([^\w\d-])10\/(1[3-9])\/([6-9]\d)(?![\w\d-])/g, '$1 October $2, 19$3');
txt.value=txt.value.replace(/([^\w\d-])11\/(1[3-9])\/([6-9]\d)(?![\w\d-])/g, '$1 November $2, 19$3');
txt.value=txt.value.replace(/([^\w\d-])12\/(1[3-9])\/([6-9]\d)(?![\w\d-])/g, '$1 December $2, 19$3');
 
// resolvable ambiguous date formats
//universal
txt .value=txt.value.replaceohc_regex(/([^-\d/:\.])\s0?1@DD\/0?1@MM\/(\d{2,4})@YYNN(?!=[^-–/\w\d-&])/ggi, '"$1@Day 1@Month January \'$2'@YYYY");
txt .value=txt.value.replaceohc_regex(/([^-\d/:\.])@DD\s0?2.@MM\/0?2\/(\d{2,4}).@YYNN(?!=[^-–/\w\d-&])/ggi, '"$1@Day 2@Month February \'$2'@YYYY");
.ohc_regex(/([^-\d/:\.])@DD[-–]@MM[-–]@YYNN(?=[^-–/\w&])/gi, "$1@Day @Month @YYYY")
txt.value=txt.value.replace(/([^\d])\s0?3\/0?3\/(\d{2,4})(?![\w\d-])/g, '$1 3 March \'$2');
txt .value=txt.value.replaceohc_regex(/([^\d]| ?)\s0?4@DD\/0?4@MM\/(\d{2,4})@YYNN(?![=\ws*\d-]|)/ggi, '"$1@Day 4@Month April \'$2'@YYYY");
txt .value=txt.value.replaceohc_regex(/([^\d]| ?)@DD\s0?5.@MM\/0?5\/(\d{2,4}).@YYNN(?![=\ws*\d-]|)/ggi, '"$1@Day 5@Month May \'$2'@YYYY");
//.ohc_regex(/(\| ?)@DD[-–]@MM[-–]@YYNN(?=\s*\|)/gi, "$1@Day @Month @YYYY");
txt.value=txt.value.replace(/([^\d])\s0?6\/0?6\/(\d{2,4})(?![\w\d-])/g, '$1 6 June \'$2');
}
txt.value=txt.value.replace(/([^\d])\s0?7\/0?7\/(\d{2,4})(?![\w\d-])/g, '$1 7 July \'$2');
txt.value=txt.value.replace(/([^\d])\s0?8\/0?8\/(\d{2,4})(?![\w\d-])/g, '$1 8 August \'$2');
txt.value=txt.value.replace(/([^\d])\s0?9\/0?9\/(\d{2,4})(?![\w\d-])/g, '$1 9 September \'$2');
txt.value=txt.value.replace(/([^\d])\s10\/10\/(\d{2,4})(?![\w\d-])/g, '$1 10 October \'$2');
txt.value=txt.value.replace(/([^\d])\s11\/11\/(\d{2,4})(?![\w\d-])/g, '$1 11 November \'$2');
txt.value=txt.value.replace(/([^\d])\s12\/12\/(\d{2,4})(?![\w\d-])/g, '$1 12 December \'$2');
 
function ohc_remove_leading_zeroes(editor) {
//UK style
editor
txt.value=txt.value.replace(/([^\w\d-][23]\d)\/0?1\/(\d{2,4})(?![\w\d-])/g, '$1 January \'$2');
txt .value=txt.value.replaceohc_regex(/(\D[^\w\d-/][23]\d)@Month\/0s@ZD@th?,?2\/(\d{2,4})s@YYYY(?![=\wW\d-]D)/ggi, '"$1@LMonth February@Day, \'$2'@LYear");
txt .value=txt.value.replaceohc_regex(/(\D[^\w\d-/][23]\d)@Month\/0s@ZD@th?3\/(\d{2,4})(?![=\wW\d-]D)/ggi, '"$1@LMonth March \'$2'@Day");
txt .value=txt.value.replaceohc_regex(/(\D[^\w\d-/][23]\d)\/0@ZD@th?4\/(s@Month\d{2,4})s@YYYY(?![=\wW\d-]D)/ggi, '"$1@Day April@LMonth \'$2'@LYear");
txt .value=txt.value.replaceohc_regex(/(\D[^\w\d-/][23]\d)\/0@ZD@th?5\/(\d{2,4})s@Month(?![=\wW\d-]D)/ggi, '"$1@Day May \'$2'@LMonth");
}
txt.value=txt.value.replace(/([^\w\d-][23]\d)\/0?6\/(\d{2,4})(?![\w\d-])/g, '$1 June \'$2');
txt.value=txt.value.replace(/([^\w\d-][23]\d)\/0?7\/(\d{2,4})(?![\w\d-])/g, '$1 July \'$2');
txt.value=txt.value.replace(/([^\w\d-][23]\d)\/0?8\/(\d{2,4})(?![\w\d-])/g, '$1 August \'$2');
txt.value=txt.value.replace(/([^\w\d-][23]\d)\/0?9\/(\d{2,4})(?![\w\d-])/g, '$1 September \'$2');
txt.value=txt.value.replace(/([^\w\d-][23]\d)\/10\/(\d{2,4})(?![\w\d-])/g, '$1 October \'$2');
txt.value=txt.value.replace(/([^\w\d-][23]\d)\/11\/(\d{2,4})(?![\w\d-])/g, '$1 November \'$2');
txt.value=txt.value.replace(/([^\w\d-][23]\d)\/12\/(\d{2,4})(?![\w\d-])/g, '$1 December \'$2');
txt.value=txt.value.replace(/([^\w\d-]1[3-9])\/0?1\/(\d{2,4})(?![\w\d-])/g, '$1 January \'$2');
txt.value=txt.value.replace(/([^\w\d-]1[3-9])\/0?2\/(\d{2,4})(?![\w\d-])/g, '$1 February \'$2');
txt.value=txt.value.replace(/([^\w\d-]1[3-9])\/0?3\/(\d{2,4})(?![\w\d-])/g, '$1 March \'$2');
txt.value=txt.value.replace(/([^\w\d-]1[3-9])\/0?4\/(\d{2,4})(?![\w\d-])/g, '$1 April \'$2');
txt.value=txt.value.replace(/([^\w\d-]1[3-9])\/0?5\/(\d{2,4})(?![\w\d-])/g, '$1 May \'$2');
txt.value=txt.value.replace(/([^\w\d-]1[3-9])\/0?6\/(\d{2,4})(?![\w\d-])/g, '$1 June \'$2');
txt.value=txt.value.replace(/([^\w\d-]1[3-9])\/0?7\/(\d{2,4})(?![\w\d-])/g, '$1 July \'$2');
txt.value=txt.value.replace(/([^\w\d-]1[3-9])\/0?8\/(\d{2,4})(?![\w\d-])/g, '$1 August \'$2');
txt.value=txt.value.replace(/([^\w\d-]1[3-9])\/0?9\/(\d{2,4})(?![\w\d-])/g, '$1 September \'$2');
txt.value=txt.value.replace(/([^\w\d-]1[3-9])\/10\/(\d{2,4})(?![\w\d-])/g, '$1 October \'$2');
txt.value=txt.value.replace(/([^\w\d-]1[3-9])\/11\/(\d{2,4})(?![\w\d-])/g, '$1 November \'$2');
txt.value=txt.value.replace(/([^\w\d-]1[3-9])\/12\/(\d{2,4})(?![\w\d-])/g, '$1 December \'$2');
 
function ohc_delink_dates(editor) {
//US style
editor
txt.value=txt.value.replace(/([^\w\d-])0?1\/([23]\d)\/(\d{2,4})(?![\w\d-])/g, '$1 January $2, \'$3');
// add missing space between wikilinks
txt.value=txt.value.replace(/([^\w\d-])0?2\/([23]\d)\/(\d{2,4})(?![\w\d-])/g, '$1 February $2, \'$3');
txt.value=txt.value .replace(/([^\w\d-])0?3\/([23]\d)\/(\d{2,4})(?![\w\d-][)/ggi, '"$1 March $2,") \'$3'// remove (?!file:); to ensure a space between all links
txt.value=txt.value.replace(/([^\w\d-])0?4\/([23]\d)\/(\d{2,4})(?![\w\d-])/g, '$1 April $2, \'$3');
txt.value=txt.value.replace(/([^\w\d-])0?5\/([23]\d)\/(\d{2,4})(?![\w\d-])/g, '$1 May $2, \'$3');
txt.value=txt.value.replace(/([^\w\d-])0?6\/([23]\d)\/(\d{2,4})(?![\w\d-])/g, '$1 June $2, \'$3');
txt.value=txt.value.replace(/([^\w\d-])0?7\/([23]\d)\/(\d{2,4})(?![\w\d-])/g, '$1 July $2, \'$3');
txt.value=txt.value.replace(/([^\w\d-])0?8\/([23]\d)\/(\d{2,4})(?![\w\d-])/g, '$1 August $2, \'$3');
txt.value=txt.value.replace(/([^\w\d-])0?9\/([23]\d)\/(\d{2,4})(?![\w\d-])/g, '$1 September $2, \'$3');
txt.value=txt.value.replace(/([^\w\d-])10\/([23]\d)\/(\d{2,4})(?![\w\d-])/g, '$1 October $2, \'$3');
txt.value=txt.value.replace(/([^\w\d-])11\/([23]\d)\/(\d{2,4})(?![\w\d-])/g, '$1 November $2, \'$3');
txt.value=txt.value.replace(/([^\w\d-])12\/([23]\d)\/(\d{2,4})(?![\w\d-])/g, '$1 December $2, \'$3');
txt.value=txt.value.replace(/([^\w\d-])0?1\/(1[3-9])\/(\d{2,4})(?![\w\d-])/g, '$1 January $2,\'$3');
txt.value=txt.value.replace(/([^\w\d-])0?2\/(1[3-9])\/(\d{2,4})(?![\w\d-])/g, '$1 February $2, \'$3');
txt.value=txt.value.replace(/([^\w\d-])0?3\/(1[3-9])\/(\d{2,4})(?![\w\d-])/g, '$1 March $2, \'$3');
txt.value=txt.value.replace(/([^\w\d-])0?4\/(1[3-9])\/(\d{2,4})(?![\w\d-])/g, '$1 April $2, \'$3');
txt.value=txt.value.replace(/([^\w\d-])0?5\/(1[3-9])\/(\d{2,4})(?![\w\d-])/g, '$1 May $2, \'$3');
txt.value=txt.value.replace(/([^\w\d-])0?6\/(1[3-9])\/(\d{2,4})(?![\w\d-])/g, '$1 June $2, \'$3');
txt.value=txt.value.replace(/([^\w\d-])0?7\/(1[3-9])\/(\d{2,4})(?![\w\d-])/g, '$1 July $2, \'$3');
txt.value=txt.value.replace(/([^\w\d-])0?8\/(1[3-9])\/(\d{2,4})(?![\w\d-])/g, '$1 August $2, \'$3');
txt.value=txt.value.replace(/([^\w\d-])0?9\/(1[3-9])\/(\d{2,4})(?![\w\d-])/g, '$1 September $2, \'$3');
txt.value=txt.value.replace(/([^\w\d-])10\/(1[3-9])\/(\d{2,4})(?![\w\d-])/g, '$1 October $2, \'$3');
txt.value=txt.value.replace(/([^\w\d-])11\/(1[3-9])\/(\d{2,4})(?![\w\d-])/g, '$1 November $2, \'$3');
txt.value=txt.value.replace(/([^\w\d-])12\/(1[3-9])\/(\d{2,4})(?![\w\d-])/g, '$1 December $2, \'$3');
 
// rem redundant quote marks and parentheses
.replace(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)\'\'\'([^|}\[\]]*)\'\'\'(?=\s*[|}])/gi, "$1$2")
.replace(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)\'\'([^|}\[\]]*)\'\'(?=\s*[|}])/gi, "$1$2")
.replace(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)\"([^|}\[\]]*)\"(?=\s*[|}])/gi, "$1$2")
.replace(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)\(([^|}\[\]]*)\)(?=\s*[|}])/gi, "$1$2")
 
// delink unpiped dates
// Add a tag to the summary box
// delink full dates
var txt=document.editform.wpSummary;
.ohc_regex(/\[\[@Day[\s_](?:of[\s_])?@Month(?:\]\]\s?\[\[\| )@YYYY\]\]/gi, "@Day @LMonth @YYYY")
var summary = "resolved [[WP:MOSNUM|ambiguous date formats]]";
.ohc_regex(/\[\[@Month (?:the\s)?@Day(?:\]\],? \[\[|, )@YYYY\]\]/gi, "@LMonth @Day, @YYYY")
if (txt.value.indexOf(summary) == -1) {
 
if (txt.value.match(/[^\*\/\s][^\/\s]?\s*$/)) {
// delink yyyy-mm-dd dates
txt.value += " | ";
.ohc_regex(/\[\[@YYYY(?:\]\]-\[\[|-)@MM-@DD\]\]/gi, "@YYYY-@MM-@DD")
}
.ohc_regex(/@YYYY-\[\[@MM-@DD\]\]/gi, "@YYYY-@MM-@DD")
txt.value += summary;
 
}
// underscore and nbsp in linked dates
document.forms.editform.wpMinoredit.checked = true;
.ohc_regex(/\[\[@DD@th?(?:\s|_|&nbsp;)@Month\]\]/gi, "@Day @LMonth")
// document.editform.wpDiff.click();
.ohc_regex(/\[\[@Month(?:\s|_|&nbsp;)@DD@th?\]\]@th?/gi, "@LMonth @Day") //consolidated regex with flexible removal of ordinal simple date
.ohc_regex(/\[\[@Day @Month\]\]/gi, "@Day @LMonth")
.ohc_regex(/\[\[@Month @YYYY\]\]/gi, "@LMonth @YYYY")
.ohc_regex(/\[\[@YYYY\]\]/gi, "@YYYY")
 
// remove leading zero and links from linked date
.ohc_regex(/\[\[@Month(?:[ _]|&nbsp;)@ZD@th\]\]/gi, "@LMonth @Day")
.ohc_regex(/\[\[@ZD@th(?:[ _]|&nbsp;)@Month\]\]/gi, "@Day @LMonth")
 
// remove nowrap template from dm and md dates
.ohc_regex(/(date[ ]*=[ ]*)\{\{(?:j|no ?(?:break|wrap))\|(?:@DD(?:[ _]|&nbsp;)@Month)( @yyyy|)\}\}/gi, "$1@DD @LMonth$2")
.ohc_regex(/(date[ ]*=[ ]*)\{\{(?:j|no ?(?:break|wrap))\|(?:@Month(?:[ _]|&nbsp;)@DD)( @yyyy|)\}\}/gi, "$1@LMonth @DD$2")
 
// delink single dm or 'dth the m'
.ohc_regex(/(?:the\s)?\[\[@Day@th?[\s_](?:of[\s_])?@Month\]\]/gi, "@Day @LMonth")
 
// delink single md or 'm the dth'
.ohc_regex(/\[\[@Month[\s_](?:the[\s_])?@Day@th?\]\](?=\W)/gi, "@LMonth @Day")
 
// month+day piped
.ohc_regex(/\[\[(?:@dd@th?[\s_](?:of[\s_])?@month|@month[\s_]@dd@th?)\|((?:@month |)@day)@th?\]\]/gi, "$1")
.ohc_regex(/\[\[(?:@dd@th?[\s_](?:of[\s_])?@month|@month[\s_]@dd@th?)\|@Day@th?[\s_](@month|)\]\]/gi, "@Day $1")
//.ohc_regex(/\[\[@month @dd(?:#[^|]+|)\|([^|\]]+)@th?\]\]/gi, "$1")
//.ohc_regex(/\[\[@dd @month(?:#[^|]+|)\|([^|\]]+)@th?\]\]/gi, "$1")
.ohc_regex(/\[\[@month @yyyy(?:#[^|]+|)\|([^|\]]+)\]\]/gi, "$1")
 
// month+day+year pseudo-ISO dates
.ohc_regex(/\[\[@Month @DD\|\d\d-\d\d\]\]-(?:\[\[)?(?:@yyyy[^|]*\|)?@YYYY(?:\]\])/gi, "@Day @LMonth @YYYY")
.ohc_regex(/\[\[@DD\s@Month\|\d\d-\d\d\]\]-(?:\[\[)?(?:@yyyy[^|]*\|)?@YYYY(?:\]\])/gi, "@Day @LMonth @YYYY")
 
//'[[month day|xxXxx]]Xyyyy ' to 'month day, year'
.ohc_regex(/\[\[@Month\s@Day\|@dd.@dd\]\].@YYYY/gi, "@LMonth @Day, @YYYY")
 
//'[[day month|xxXxx]]Xyyyy' to 'day month year'
.ohc_regex(/\[\[@Day\s@Month\|@dd.@dd\]\].@YYYY/gi, "@Day @LMonth @YYYY")
 
// century
.replace(/\[\[((?:(?:(?:thir|four|fif|six|seven|eigh|nine)teen|twentie)th|twenty[\s\-]first[\s\-])centur(?:y|ies))\]\]/gi, "$1")
.replace(/\[\[(?:(?:(?:thir|four|fif|six|seven|eigh|nine)teen|twentie)th|twenty[\s\-]first)[\s\-_]centur(?:y|ies)\|([^\]]{1,30})\]\]/gi, "$1")
.replace(/\[\[(\d{2}(?:st|[nr]d|th))[\s\-_](centur(?:y|ies))\]\]/gi, "$1 $2")
.ohc_regex(/\[\[\d{2}@th[\s\-_]centur(?:y|ies)\|([^\]]{1,30})\]\]/gi, "$1")
 
// months
.ohc_regex(/\[\[@Month\]\]/gi, "@LMonth")
.ohc_regex(/\[\[@FullMonth\|([^\]]{1,30})\]\]/gi, "$1")
 
// decades and years
.replace(/(\d{1,3}0)[‘`´’′]?s/g, "$1s")
.replace(/\[\[(\d{1,3}0)\'?s\]\]/g, "$1s")
.replace(/\[\[\d{1,3}0\'?s?\|([^\]]{1,30})\]\]/g, "$1")
// .replace(/\[\[(\d{2,3}0)\'?(s)?\s(AD|BC|CE|BCE)\]\]/gi, "$1$2 $3")
// .replace(/\[\[(\d{1,4}[\s_]?)(AD|BC|CE|BCE)\]\]/gi, "$1$2")
.replace(/\[\[(AD|BC|CE|BCE)([\s_]?)(\d{1,4})\]\]/gi, "$1$2$3")
.ohc_regex(/([-–])\[\[\s?@yyyy\s?\|\s?(\d{2,4})\s?\]\]/gi, "$1$2") // piped year
.replace(/\[\[([12]\d{3}|[1-9]\d{0,2})\]\]/gi, "$1")
.replace(/\[\[\d{1,3}0\'?s?\s(?:AD|BC|CE|BCE)\|([^\]]{1,30})\]\]/gi, "$1")
.replace(/\[\[\d{1,3}0\'?s?\s\(decade\)\|([^\]]{1,30})\]\]/gi, "$1")
 
// 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
.ohc_regex(/\[\[@yyyy in[^|\]]+\|@Day @Month @YYYY\]\]/gi, "@Day @LMonth @YYYY")
.ohc_regex(/\[\[@yyyy in[^|\]]+\|@Month @Day,? @YYYY\]\]/gi, "@LMonth @Day, @YYYY")
.ohc_regex(/\[\[@yyyy#[^|\]]+\|(@month\s|)(@yyyy)\]\]/gi, "$1$2")
.ohc_regex(/\[\[@yyyy#[^|\]]+\|(@month|@yyyy)\]\]/gi, "$1")
.ohc_regex(/\[\[(@month\s@yyyy)\]\]/gi, "$1")
.ohc_regex(/\[\[@month\s@yyyy\|([^\]]{1,30})\]\]/gi, "$1")
.ohc_regex(/\[\[(?:List of |)Bollywood films of @yyyy\|@YYYY\]\](?= [^\[]{2}^B)/gi, "@YYYY")
 
.ohc_regex(/(\[\[@yyyy[^|\]]+\|@yyyy)(\]\])( season)/gi, "$1$3$2")
 
// removed piped years when in full date (excepting disambiguated parentheses - updated 24/2/2012)
//.ohc_regex(/\[\[[^|\]\(\)]{1,32}\|@YYYY\]\]/gi, "@Year"); // 23/6/2021 – disabled delinking "other" year-in articles
 
// Identify surprise or 'Easter egg' diversions linking months to year or "year in" articles.
.ohc_regex(/\[\[\d{1,4}#[^|\]]+\|@Month\]\]/gi, "@LMonth")
// .ohc_regex(/\[\[@yyyy \w[^|\]]{3,12}\|@Year\]\]/gi, "@Year") //disable easter egg removal per request 5 November 2022
 
// month and day piped
.ohc_regex(/\[\[@month[\s_]@day\|@MM-@DD\]\]/gi, "@MM-@DD")
.ohc_regex(/\[\[@month[\s_]@day\|([^\]]{1,30})\]\]/gi, "$1")
.ohc_regex(/\[\[@day(?:\s|_|@th )(?:of[\s_]|)?@month\|([^\]]{1,30})\]\]/gi, "$1")
 
// years piped
.replace(/\[\[\d{1,4}\|([^\]]{1,30})\]\]/gi, "$1");
}
 
function ohc_fix_common_errors(editor) {
//////
editor
function Ohc_US_slash_dates(){
.ohc_regex(/(\d)<sup>@th<\/sup>/gi, "$1th")
var txt=document.editform.wpTextbox1;
// resolvable ambiguous date formats
 
// remove dashbot comment from dates
//4-digit year US style
.replace(/<!-- ?DASHBot ?-->/gi, '')
txt.value=txt.value.replace(/([^\w\d-])0?1\/([0-3]\d)\/(\d{4})(?![\w\d-])/g, '$1 January $2, $3');
.ohc_regex(/(\|\s*(?:date|year)\s*=)\s*c(?:irca|a\.)?\s?((?:@day |)@month @year)(?=[\s\n]*[<|}])/gi, "$1c. $2") // add space
txt.value=txt.value.replace(/([^\w\d-])0?2\/([0-3]\d)\/(\d{4})(?![\w\d-])/g, '$1 February $2, $3');
txt.value=txt.value.replace(/([^\w\d-])0?3\/([0-3]\d)\/(\d{4})(?![\w\d-])/g, '$1 March $2, $3');
txt.value=txt.value.replace(/([^\w\d-])0?4\/([0-3]\d)\/(\d{4})(?![\w\d-])/g, '$1 April $2, $3');
txt.value=txt.value.replace(/([^\w\d-])0?5\/([0-3]\d)\/(\d{4})(?![\w\d-])/g, '$1 May $2, $3');
txt.value=txt.value.replace(/([^\w\d-])0?6\/([0-3]\d)\/(\d{4})(?![\w\d-])/g, '$1 June $2, $3');
txt.value=txt.value.replace(/([^\w\d-])0?7\/([0-3]\d)\/(\d{4})(?![\w\d-])/g, '$1 July $2, $3');
txt.value=txt.value.replace(/([^\w\d-])0?8\/([0-3]\d)\/(\d{4})(?![\w\d-])/g, '$1 August $2, $3');
txt.value=txt.value.replace(/([^\w\d-])0?9\/([0-3]\d)\/(\d{4})(?![\w\d-])/g, '$1 September $2, $3');
txt.value=txt.value.replace(/([^\w\d-])10\/([0-3]\d)\/(\d{4})(?![\w\d-])/g, '$1 October $2, $3');
txt.value=txt.value.replace(/([^\w\d-])11\/([0-3]\d)\/(\d{4})(?![\w\d-])/g, '$1 November $2, $3');
txt.value=txt.value.replace(/([^\w\d-])12\/([0-3]\d)\/(\d{4})(?![\w\d-])/g, '$1 December $2, $3');
 
// common cs1 errors
//2-digit year ('00-'19) US style
txt.value=txt.value .replace(/([^\w|\d-]s*(?:date|year)0?1\/s*=)\s*(1[07-39]\d)\/(|20[010-1]\d)\?(?!=[\ws\d-n]*[<|}])/ggi, '"$1 January1c. $2, 20$3'");
txt.value=txt.value .replace(/([^\w|\d-]s*(?:date|year)0?2\/s*=\s*(1[07-39])\d{2})\/([01-–](\d{2})(?!=[\ws\d-n]*[<|}])/ggi, '"$1 February 1–$2, 20$3'");
txt.value=txt.value //.replace(/([^\w|\d-]s*(?:date|year)0?3\/s*=\s*(20)[0-31]\d)\/[-–]([010-2]\d)(?!=[\ws\d-n]*[<|}])/ggi, '"$1 March 1–$2, 20$3'");
.ohc_regex(/(\|\s*(?:date|year)\s*=\s*)@YYYY\s*[-–/]\s*@YYNN(?=[\s\n]*[<|}])/gi, "$1@YYYY1–@YYYY2") // common cs1 error(/(\|\s*(?:date|year)\s*=\s*)@YYYY\s*[-–/]\s*@YYYY(?=[\s\n]*[<|}])/gi, "$1@YYYY1–@YYYY2") //common cs1 error
txt.value=txt.value.replace(/([^\w\d-])0?4\/([0-3]\d)\/([01]\d)(?![\w\d-])/g, '$1 April $2, 20$3');
txt.value=txt.value .replace(/([^\w|\d-]s*(?:date)0\s*=)\s*s(pring|ummer),?5\/s*((?:1[07-39]\d)\/(|20[010-1])\d)(?!=[\ws\d-n]*[<|}])/ggi, '"$1 May 1S$2, 20$3'"); // common cs1 error
txt.value=txt.value .replace(/([^\w|\d-]s*(?:date)0\s*=)\s*a(utumn),?6\/s*((?:1[07-39]\d)\/(|20[010-1])\d)(?!=[\ws\d-n]*[<|}])/ggi, '"$1 June 1A$2, 20$3'"); // common cs1 error
txt.value=txt.value .replace(/([^\w|\d-]s*(?:date)0\s*=)\s*f(all),?7\/s*((?:1[07-39]\d)\/(|20[010-1])\d)(?!=[\ws\d-n]*[<|}])/ggi, '"$1 July 1F$2, 20$3'"); // common cs1 error
txt.value=txt.value .replace(/([^\w|\d-]s*(?:date)0\s*=)\s*w(inter),?8\/s*((?:1[07-39]\d)\/(|20[010-1])\d)(?!=[\ws\d-n]*[<|}])/ggi, '"$1 August 1W$2, 20$3'"); // common cs1 error
.replace(/(\|\s*(?:date)\s*=)\s*(Spring|Summer|Autumn|Fall|Winter)[-–](S(?:pring|ummer)|Autumn|Fall|Winter) ?/gi, "$1$2–$3 ") // common cs1 error
txt.value=txt.value.replace(/([^\w\d-])0?9\/([0-3]\d)\/([01]\d)(?![\w\d-])/g, '$1 September $2, 20$3');
txt .value=txt.value.replaceohc_regex(/([^\w|\ds*access-])10?date\/([0-3]\ds*=)\/s*([01]\d@month @year)(?!=[\ws\d-n]*[<|}])/ggi, '"$1 October11 $2,") 20$3');//common cs1 error
//.ohc_regex(/(\|\s*date\s*=\s*)@year\?(?=[\s\n]*[<|}])/gi, "$1@Year") // common cs1 error
txt.value=txt.value.replace(/([^\w\d-])11\/([0-3]\d)\/([01]\d)(?![\w\d-])/g, '$1 November $2, 20$3');
//.ohc_regex(/(\|\s*(?:date|year)\s*=)\s*@year\?(?=[\s\n]*[<|}])/gi, "$1c. @Year") // common cs1 error
txt.value=txt.value.replace(/([^\w\d-])12\/([0-3]\d)\/([01]\d)(?![\w\d-])/g, '$1 December $2, 20$3');
//.ohc_regex(/(\|\s*(?:date|year)\s*=)\s*(@month @year)\?(?=[\s\n]*[<|}])/gi, "$1c. $2") // common cs1 error
.ohc_regex(/(\|\s*access-?date\s*=)\s*@month @day, (1[7-9]\d{2}|2000)(?=[\s\n]*[<|}])/gi, "$1") // rem access date before Wikipedia (January 2001)
.ohc_regex(/(\|\s*access-?date\s*=)\s*@day @month.? (1[7-9]\d{2}|2000)(?=[\s\n]*[<|}])/gi, "$1") // rem access date before Wikipedia (January 2001)
.ohc_regex(/(\|\s*access-?date\s*=)\s*31( (?:April|June|September|November) @year)(?=[\s\n]*[<|}])/gi, "$130$2") // rem nonsense access date (short months)
.ohc_regex(/(\|\s*access-?date\s*=)\s*29( February (?:200[1235679]|201[1345789]))(?=[\s\n]*[<|}])/gi, "$128$2") // rem nonsense access date 29 Feb (non-leap year)
.ohc_regex(/(\|\s*access-?date\s*=)\s*(?:3[01])( February @yyyy)(?=[\s\n]*[<|}])/gi, "$128$2") // rem nonsense access dates February
.replace(/(\|\s*access-?date\s*=)\s*(\d{4})(?=[\s\n]*[<|}])/gi, '') // common cs1 error
 
//2-digit month+day+year ('60pseudo-'99) USISO styledates
.ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*@dd)-@Mon-@YYYY/gi, "$1 @FullMonth @YYYY")
txt.value=txt.value.replace(/([^\w\d-])0?1\/([0-3]\d)\/([6-9]\d)(?![\w\d-])/g, '$1 January $2, 19$3');
.ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)@YYYY-@DD-@Mon/gi, "$1 @DD @FullMonth @YYYY")
txt.value=txt.value.replace(/([^\w\d-])0?2\/([0-3]\d)\/([6-9]\d)(?![\w\d-])/g, '$1 February $2, 19$3');
txt.value=txt.value.replace(/([^\w\d-])0?3\/([0-3]\d)\/([6-9]\d)(?![\w\d-])/g, '$1 March $2, 19$3');
txt.value=txt.value.replace(/([^\w\d-])0?4\/([0-3]\d)\/([6-9]\d)(?![\w\d-])/g, '$1 April $2, 19$3');
txt.value=txt.value.replace(/([^\w\d-])0?5\/([0-3]\d)\/([6-9]\d)(?![\w\d-])/g, '$1 May $2, 19$3');
txt.value=txt.value.replace(/([^\w\d-])0?6\/([0-3]\d)\/([6-9]\d)(?![\w\d-])/g, '$1 June $2, 19$3');
txt.value=txt.value.replace(/([^\w\d-])0?7\/([0-3]\d)\/([6-9]\d)(?![\w\d-])/g, '$1 July $2, 19$3');
txt.value=txt.value.replace(/([^\w\d-])0?8\/([0-3]\d)\/([6-9]\d)(?![\w\d-])/g, '$1 August $2, 19$3');
txt.value=txt.value.replace(/([^\w\d-])0?9\/([0-3]\d)\/([6-9]\d)(?![\w\d-])/g, '$1 September $2, 19$3');
txt.value=txt.value.replace(/([^\w\d-])10\/([0-3]\d)\/([6-9]\d)(?![\w\d-])/g, '$1 October $2, 19$3');
txt.value=txt.value.replace(/([^\w\d-])11\/([0-3]\d)\/([6-9]\d)(?![\w\d-])/g, '$1 November $2, 19$3');
txt.value=txt.value.replace(/([^\w\d-])12\/([0-3]\d)\/([6-9]\d)(?![\w\d-])/g, '$1 December $2, 19$3');
 
.replace(/(\|\s*(?:date|year)\s*=)\s*(?:(?:date |)unknown|(?:not? |non-|un)date[ds])(?=[\s\n]*[<|}])/gi, "$1n.d.") // common cs1 error
.replace(/(\|\s*(?:date|year)\s*=)\s*n\.?d(?=[\s\n]*[<|}])/gi, "$1n.d.") // common cs1 error
.replace(/(\|\s*)year(\s*=\s*)(?=n\.?d\.)(?=[\s\n]*[<|}])/gi, "$1date$2") // common cs1 error
 
// remove parasitic metadata - days of the week/descriptives
// Add a tag to the summary box
.ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)(?:[^|}\d]*|)@Day\s+@Month\s+@YYYY((?:[a-z]\b|)\s?)(?=[\s\n]*[<|}])/gi, "$1@Day @Month @YYYY$2") // rem negate "<", "hyphens" "dashes" 26/6/2020
var txt=document.editform.wpSummary;
.ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)[^|}]*@Month\s+@Day,\s+@YYYY((?:[a-z]\b|)\s?)(?=[\s\n]*[<|}])/gi, "$1@Month @Day, @YYYY$2") // rem negate "<", "hyphens" "dashes" 26/6/2020
var summary = "resolved [[WP:MOSNUM|ambiguous date formats]]";
//.ohc_regex(/(\|\s*date\s*=\s*)(?:[^|}–<]*\D|)@Day\s+@Month\s+@YYYY ?– ?@Day\s+@Month\s+@YYYY[^|}–<]*(?=[\s\n]*[<|}])/gi, "$1@Day1 @Mon1 @Year1 – @Day2 @Mon2 @Year2")
if (txt.value.indexOf(summary) == -1) {
//.ohc_regex(/(\|\s*date\s*=\s*)[^|}–<]*@Month\s+@Day,\s+@YYYY ?– ?@Month @Day, @YYYY[^|}–<]*(?=[\s\n]*[<|}])/gi, "$1@Mon1 @Day1, @Year1 – @@Mon2 Day2, @Year2")
if (txt.value.match(/[^\*\/\s][^\/\s]?\s*$/)) {
//.replace(/(\|\s*author\s*=\s*)(?:posted|published)(?: by\b| on\b|)[\s:](?=\w)/gi, "$1")
txt.value += " | ";
//.replace(/(\|\s*(?:date|archive-?date|access-?date|author|year)\s*=\s*)(?:accessed|retrieved|entered|posted|published|(?:last |)updated?|©)(?: by\b| on\b|)[\s:]*(?=\w)/gi, "$1")
}
.replace(/(\|\s*(?:author|first|last)\s*=\s*)(?:by\b|on\b)[\s:]*(?=\w)/gi, "$1")
txt.value += summary;
.replace(/(\|\s*(?:date|archive-?date|access-?date|author|first|last)\s*=\s*)(?:(?:Mon|Tues|Wednes|Thurs|Fri|Satur|Sun)day,?)\s/gi, "$1")
}
.replace(/(\|\s*(?:date|archive-?date|access-?date|author|first|last)\s*=\s*)(?:Mon|Tues?|Wed|Thur?|Fri|Sat)[\.,]?\s/gi, "$1") // rem "Sun" - false positives
document.forms.editform.wpMinoredit.checked = true;
 
// document.editform.wpDiff.click();
// remove deprecated parameters (|day= and |month)
.ohc_regex(/(\|\s*)day(?:\s*=\s*)@DD ?\| ?month(?:\s*=\s*)@Month ?\| ?year(?:\s*=\s*)@YYYY(?=[|}\s])/gi, "$1date=@Day @Month @Year")
.ohc_regex(/(\|\s*)year(?:\s*=\s*)@YYYY ?\| ?month(?:\s*=\s*)@Month ?\| ?day(?:\s*=\s*)@DD(?=[|}\s])/gi, "$1date=@Month @Day, @Year")
 
// typos
.ohc_regex(/(date *= *)@Day @Month ?@th/gi, "$1@Day @Month")
.ohc_regex(/(date *= *)@Day @Month\w(?= \d{3,4})/gi, "$1@Day @Month")
 
.ohc_regex(/(date *= *(?:[12]?\d|30|31) )(Jan|Febr)[\w ]?[aur]{3,4}\w{0,2}(?= (?:1[6-9]\d|20[01])\d\b)/gi, "$1$2uary")
.ohc_regex(/(date *= *(?:[12]?\d|30|31) )J[anu]{3,5}r\w{0,2}(?= (?:1[6-9]\d|20[01])\d\b)/gi, "$1January")
.ohc_regex(/(date *= *(?:[12]?\d) )Febua?r\w{0,2}(?= (?:1[6-9]\d|20[01])\d\b)/gi, "$1February")
.ohc_regex(/(date *= *(?:[12]?\d|30|31) )M\w{2,3}ch(?= (?:1[6-9]\d|20[01])\d\b)/gi, "$1March")
.ohc_regex(/(date *= *(?:[12]?\d|30) )A[bpv\[]\w{2,3}l\w?(?= (?:1[6-9]\d|20[01])\d\b)/gi, "$1April")
.ohc_regex(/(date *= *(?:[12]?\d|30|31) )Ma[tui](?= (?:1[6-9]\d|20[01])\d\b)/gi, "$1May")
.ohc_regex(/(date *= *(?:[12]?\d|30) )J\wn\w(?= (?:1[6-9]\d|20[01])\d\b)/gi, "$1June")
.ohc_regex(/(date *= *(?:[12]?\d|30) )J\w{1,2}e(?= (?:1[6-9]\d|20[01])\d\b)/gi, "$1June")
.ohc_regex(/(date *= *(?:[12]?\d|30|31) )Jul\w{1,2}(?= (?:1[6-9]\d|20[01])\d\b)/gi, "$1July")
.ohc_regex(/(date *= *(?:[12]?\d|30|31) )A[oug]{2,3}\w{1,4}t(?:\w|us)?(?= (?:1[6-9]\d|20[01])\d\b)/gi, "$1August")
.ohc_regex(/(date *= *(?:[12]?\d|30|31) )(Sept|Nov|Dec)\w{2,4}b[er]{1,2}\w?(?= (?:1[6-9]\d|20[01])\d\b)/gi, "$1$2ember")
.ohc_regex(/(date *= *(?:[12]?\d|30) )S\w{0,2}p[ \[]?\w{2,5}[er]{2,3}\w?(?= (?:1[6-9]\d|20[01])\d\b)/gi, "$1September")
.ohc_regex(/(date *= *(?:[12]?\d|30|31) )O\w{0,2}t\w{1,3}[er]{2,3}\w?(?= (?:1[6-9]\d|20[01])\d\b)/gi, "$1October")
.ohc_regex(/(date *= *(?:[12]?\d|30) )[MN]\w{1,2}[bv] ?\w{1,3}b[er]{1,2}\w?(?= (?:1[6-9]\d|20[01])\d\b)/gi, "$1November")
.ohc_regex(/(date *= *(?:[12]?\d|30|31) )D[ie]?[cs] ?\w{1,4}b[er]{1,2}\w?(?= (?:1[6-9]\d|20[01])\d\b)/gi, "$1December")
 
.ohc_regex(/(date *= *)@Month\w(?=(?: (?:[12]?\d|30|31),?|) (?:1[6-9]\d|20[01])\d\b)/gi, "$1@Month") //rem stray digit at the end of year string
 
.ohc_regex(/(date *= *)(Jan|Febr)[\w ]?[aur]{3,4}\w{0,2}(?=(?: (?:[12]?\d|30|31),?|) (?:1[6-9]\d|20[01])\d\b)/gi, "$1$2uary")
.ohc_regex(/(date *= *)J[anu]{3,5}r\w{0,2}(?=(?: (?:[12]?\d|30|31),?|) (?:1[6-9]\d|20[01])\d\b)/gi, "$1January")
.ohc_regex(/(date *= *)Febua?r\w{0,2}(?=(?: (?:[12]?\d),?|) (?:1[6-9]\d|20[01])\d\b)/gi, "$1February")
.ohc_regex(/(date *= *)M\w{2,3}ch(?=(?: (?:[12]?\d|30|31),?|) (?:1[6-9]\d|20[01])\d\b)/gi, "$1March")
.ohc_regex(/(date *= *)A[bpv\[]\w{2,3}l\w?(?=(?: (?:[12]?\d|30),?|) (?:1[6-9]\d|20[01])\d\b)/gi, "$1April")
.ohc_regex(/(date *= *)Ma[tui](?=(?: (?:[12]?\d|30|31),?|) (?:1[6-9]\d|20[01])\d\b)/gi, "$1May")
.ohc_regex(/(date *= *)J\wn\w(?=(?: (?:[12]?\d|30),?|) (?:1[6-9]\d|20[01])\d\b)/gi, "$1June")
.ohc_regex(/(date *= *)J\w{1,2}e(?=(?: (?:[12]?\d|30),?|) (?:1[6-9]\d|20[01])\d\b)/gi, "$1June")
.ohc_regex(/(date *= *)Jul\w{1,2}(?=(?: (?:[12]?\d|30|31),?|) (?:1[6-9]\d|20[01])\d\b)/gi, "$1July")
.ohc_regex(/(date *= *)A[oug]{2,3}\w{1,4}t(?:\w|us)?(?=(?: (?:[12]?\d|30|31),?|) (?:1[6-9]\d|20[01])\d\b)/gi, "$1August")
.ohc_regex(/(date *= *)(Sept|Nov|Dec)\w{2,4}b[er]{1,2}\w?(?=(?: (?:[12]?\d|30|31),?|) (?:1[6-9]\d|20[01])\d\b)/gi, "$1$2ember")
.ohc_regex(/(date *= *)S\w{0,2}p[ \[]?\w{2,5}[er]{2,3}\w?(?=(?: (?:[12]?\d|30),?|) (?:1[6-9]\d|20[01])\d\b)/gi, "$1September")
.ohc_regex(/(date *= *)O\w{0,2}t\w{1,3}[er]{2,3}\w?(?=(?: (?:[12]?\d|30|31),?|) (?:1[6-9]\d|20[01])\d\b)/gi, "$1October")
.ohc_regex(/(date *= *)[MN]\w{1,2}[bv] ?\w{1,3}b[er]{1,2}\w?(?=(?: (?:[12]?\d|30),?|) (?:1[6-9]\d|20[01])\d\b)/gi, "$1November")
.ohc_regex(/(date *= *)D[ie]?[cs] ?\w{1,4}b[er]{1,2}\w?(?=(?: (?:[12]?\d|30|31),?|) (?:1[6-9]\d|20[01])\d\b)/gi, "$1December")
 
// insert comma to separate date from army unit
.ohc_regex(/@FullMonth ((?:the |)\d\d*@th (?:Air(?:borne|)|Arm(?:ou?red|y)|Artillery|Battalion|Brigade|Co(?:mpan|)y|Division|Fleet|Group|Infantry|Land|Panzer|Regiment|Squadron|Sqn)\b)/g, "@Month, $1")
 
// remove parasitic metadata - time
.ohc_regex(/(\|\s*\w*date\s*=\s*@yyyy-@mm-@dd)\s?(?:T[0-2]\d:[0-5]\d:[0-5]\d(?:\s*|&nbsp;|)(?:GMT\s*|UTC\s*|[A-Z]{1,2}[DS]T\s*|Z))(?=\s*[|}])/g, "$1")
.ohc_regex(/(\|\s*\w*date\s*=\s*@month @day,? @yyyy)\s?(?:,? [0-2]?\d[\.:][0-5]\d(?:\s*|&nbsp;)(?:[apAP][mM]\s*|)(?:GMT\s*|UTC\s*|[A-Z]{1,2}[DS]T\s*|))(?=\|)/g, "$1")
.ohc_regex(/(\|\s*\w*date\s*=\s*@day @month,? @yyyy)\s?(?:,? [0-2]?\d[\.:][0-5]\d(?:\s*|&nbsp;)(?:[apAP][mM]\s*|)(?:GMT\s*|UTC\s*|[A-Z]{1,2}[DS]T\s*|))(?=\|)/g, "$1")
.ohc_regex(/(\|\s*\w*date\s*=\s*\w[\w\s]+@month @day,? @yyyy)\s?(?:,? [0-2]?\d[\.:][0-5]\d(?:\s*|&nbsp;)(?:[apAP][mM]\s*|)(?:GMT\s*|UTC\s*|[A-Z]{1,2}[DS]T\s*|))(?=\|)/g, "$1")
.ohc_regex(/(\|\s*\w*date\s*=\s*\w[\w\s]+@day @month,? @yyyy)\s?(?:,? [0-2]?\d[\.:][0-5]\d(?:\s*|&nbsp;)(?:[apAP][mM]\s*|)(?:GMT\s*|UTC\s*|[A-Z]{1,2}[DS]T\s*|))(?=\|)/g, "$1")
.ohc_regex(/(\|\s*\w*date\s*=[^:|}]*)\s?(?:T?[0-2]\d:[0-5]\d:[0-5]\d(?:\s*|&nbsp;|)(?:GMT\s*|UTC\s*|[A-Z]{1,2}[DS]T\s*|Z))/g, "$1")
 
// add back spaces or comma or remove other single artefact after date string
.ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)(?:on |)@Day\s{,2}@Month\s{,2}@YYYY[^a-z{}]?(?=\s*[|}\n])/gi, "$1@Day @Month @YYYY$2")
.ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)(?:on |)@Month\s{,2}@Day,?\s{,2}@YYYY[^a-z{}]?(?=\s*[|}\n])/gi, "$1@Month @Day, @YYYY$2")
 
// long-hand palliative for observed failure to insert spaces
.ohc_regex(/(\|\s*(?:archive|access|air)-?date\s*=\s*)(?:on |)([0-2]?\d|30|31)\s*(January|February|March|April|May|June|July|August|September|October|November|December)\s*((?:19\d|20[0-1])\d\s?)[^|{}\s<>]*(?=\s*[|}])/gi, "$1$2 $3 $4")
 
// remove extraneous bracket //from Batty
.ohc_regex(/{{(\s*[Cc]it(?:e|ation))([^}]+)(\s*\|\s*(?:archive-?|access-?|publication-?)?date\s*=\s*)([\w\s-]+)\](?=\s*[\|}<])/gi, "{{$1$2$3$4")
 
// fix bda template redirect
//.replace(/\{\{bda\|([^}]+)\}\}/gi, "{{birth date and age|$1}}")
//.replace(/\{\{dda\|([^}]+)\}\}/gi, "{{death date and age|$1}}")
 
// zap redundant {{date}}, {{accessdate}} {{retrieved}}, {{monthname}} and {{#dateformat}}
//.replace(/({{(?:end|start)[-–]date)\|df=y(?:es|)/gi, "$1") // rem deprecated parameter - disabled: doesn't work here, so ejected to the formatting script
.ohc_regex(/{{#formatdate:@YYYY-@MM-@DD(?:[^\}]*)}}/gi, "@Day @Month @YYYY")
.replace(/{{#formatdate:([^}]+)}}/gi, "$1")
.replace(/\{\{#dateformat:([^}\|]+)(?:\|dmy|\|mdy)?\}\}/gi, "$1")
//.ohc_regex(/(date[ ]*=[ ]*)\{\{(?:Start|End) ?date(?:\|df=y(?:es|)|)\|@YYYY\|@MM\|@DD(?:\|df=y(?:es|)|)\}\}/gi, "$1@Month @DD, @YYYY") // stripping start/end template notes inside "|date=" parameter (line 72)
.ohc_regex(/{{#formatdate:@YYYY-@MM-@DD(?:\|(?:[dmy]{3}|iso)|)}}/gi, "@Day @Month @YYYY")
.ohc_regex(/\|\s*(?:archive|access|air)-?date\s*=\s*\{\{date\}\}(?=\s*[|}])/gi, "") //remove {{date}} template without parameters that inappropriately return crrent date
.ohc_regex(/\{\{date\|@YYYY-@MM-@DD\}\}/gi, "@YYYY-@MM-@DD")
.ohc_regex(/\{\{date\|@YYYY\/@MM\/@DD\}\}/gi, "@YYYY-@MM-@DD") //remove {{date}} template while rectifying slash dates within the template
.ohc_regex(/\{\{date\|(@DD[\-\s]@Mon|@Mon[\-\s]@DD)\}\}/gi, "@Day @Month")
.replace(/\{\{date\|([^}\|]+)(?:\|l?(?:[dmy]{3}|iso|none|link))?\}\}/gi, "$1")
.ohc_regex(/[ ]*\{\{accessdate\|@YYYY-@MM-@DD[ ]*\}\}/gi, " Retrieved @YYYY-@MM-@DD")
.ohc_regex(/[ ]*\{\{retrieved[ ]*\|[ ]accessdate=([\-\w, ]*)\}\}/gi, " Retrieved $1")
//.ohc_regex(/(date[ ]*=[ ]*|\w{2,}[ ]*)\{\{(?:start|end).date[^|}]*(?:\|df=y(?:es|)|)\|@YYYY(?:\|df=y(?:es|)|)\}\}/gi, "$1@YYYY") // stripping start/end template (disabling to placate Pigsonthewing)
//.ohc_regex(/\{\{(?:Start|End) date(?:\|df=y(?:es|)|)\|@YYYY\|@MM\}\}/gi, "@Month @YYYY") // tripping start/end template notes
//.ohc_regex(/<!--(?:Use)? \{\{(?:Start|End) date\|@YYYY\|@MM\|@DD\}\} -->/gi, '') // stripping start/end template notes
.ohc_regex(/(\{\{MONTHNAME\|@MM\}\})/gi, "@Month")
 
// expand one and two-digit years in ranges
.replace(/(\()@Month @YYYY[-–]@Month @YYNN(\))/gi, "$1@Month1 @YYYY1 – @Month2 @YYYY2$2")
.replace(/(\(1[789])(\d)(1)[-–]([2-9]\))/gi, "$1$2$3–$2$4")
.replace(/(\(1[789])(\d)(2)[-–]([3-9]\))/gi, "$1$2$3–$2$4")
.replace(/(\(1[789])(\d)(3)[-–]([4-9]\))/gi, "$1$2$3–$2$4")
.replace(/(\(1[789])(\d)(4)[-–]([5-9]\))/gi, "$1$2$3–$2$4")
.replace(/(\(1[789])(\d)(5)[-–]([6-9]\))/gi, "$1$2$3–$2$4")
.replace(/(\(1[789])(\d)(6)[-–]([7-9]\))/gi, "$1$2$3–$2$4")
.replace(/(\(1[789])(\d)(7)[-–]([8-9]\))/gi, "$1$2$3–$2$4")
.replace(/(\(1[789])(\d)(8)[-–](9\))/gi, "$1$2$3–$2$4")
.replace(/(\(20)([01])(1)[-–]([2-9]\))/gi, "$1$2$3–$2$4")
.replace(/(\(20)([01])(2)[-–]([3-9]\))/gi, "$1$2$3–$2$4")
.replace(/(\(20)([01])(3)[-–]([4-9]\))/gi, "$1$2$3–$2$4")
.replace(/(\(20)([01])(4)[-–]([5-9]\))/gi, "$1$2$3–$2$4")
.replace(/(\(20)([01])(5)[-–]([6-9]\))/gi, "$1$2$3–$2$4")
.replace(/(\(20)([01])(6)[-–]([7-9]\))/gi, "$1$2$3–$2$4")
.replace(/(\(20)([01])(7)[-–]([8-9]\))/gi, "$1$2$3–$2$4")
.replace(/(\(20)([01])(8)[-–](9\))/gi, "$1$2$3–$2$4")
 
.ohc_regex(/(\W)@DD@th?, @DD@th?((?:[ ]|&nbsp;)(?:and|&|to|or)(?:[ ]|&nbsp;))@DD@th?(?:\sof\s?)?([ ]|&nbsp;)@Month(?=\W)/gi, "$1@Day1, @Day2$2@Day3$3@LMonth")
.ohc_regex(/(\W)@DD@th?((?:[ ]|&nbsp;)(?:and|&|to|or)(?:[ ]|&nbsp;))@DD@th?(?:\sof\s?|)([ ]|&nbsp;)@Month(?=\W)/gi, "$1@Day1$2@Day2$3@LMonth")
.ohc_regex(/(\W)the @DD@th(?:\sof|)\s@Month,? @YYYY(?=\W\D)/g, "$1@Day @LMonth @YYYY")
.ohc_regex(/(\W)the @DD@th(?:\sof|)\s@Month(?=\W\D)/g, "$1@Day @LMonth")
.ohc_regex(/(\W)@Day@th?(?:\sof|)([ _]|&nbsp;|{{(?:break|nbsp)}})@Month(?=[^|\]\w])/gi, "$1@Day$2@LMonth")
.ohc_regex(/(\W)@Month\s(?:the\s)?@DD@th?,(?:\sthe\s)?(?: |&nbsp;)@DD@th?(\s(?:and|&|to|or)(?:[ _]|&nbsp;))(?:the\s)?@DD@th?(?=[^|\]\w])/gi, "$1@LMonth @Day1, @Day2$2@Day3")
.ohc_regex(/(\W)(@month)\s(@day)((?:,\s@day){0,6}),?(\/|\s?[-–]\s?|\s(?:and|&|to|or)\s+?)@Day@th?(?:,?(?:[ _]|&nbsp;)|\sof\s)?(\d{3,4}\W\D)/gi, "$1$2 $3$4$5@Day, $6")
.ohc_regex(/(\W)(@month)\s(@day)((?:,\s@day){0,6}),?(\/|\s?[-–]\s?|\s(?:and|&|to|or)\s+?)@Day@th?(?=\W\D)/gi, "$1$2 $3$4$5@Day")
.ohc_regex(/(\W)@Month([ _]|&nbsp;|{{(?:break|nbsp)}})(?:the\s)?@DD@th?,? @Year/gi, "$1@LMonth$2@Day, @Year")
.ohc_regex(/(\W)@Month @Day(?:\sof|,|)([ _]|&nbsp;|{{(?:break|nbsp)}})@Year(?=[^|\]\w])/gi, "$1@Month @Day,$2@Year")
 
// consolidating/amalgamating date fields
.ohc_regex(/(\|[ ]*date[ ]*=[ ]*@day)\s*\|[ ]*month=[ ]*(@month)\s*\|[ ]*year=[ ]*(@yyyy[ ]*)(?=[|}\s])/gi, "$1 $2 $3")
.ohc_regex(/(\|[ ]*date[ ]*=[ ]*@day.?@month)\s*\|[ ]*year=[ ]*(@yyyy[ ]*)(?=[|}\s])/gi, "$1 $2")
.ohc_regex(/(\|[ ]*date[ ]*=[ ]*@month.?@day)\s*\|[ ]*year=[ ]*(@yyyy[ ]*)(?=[|}\s])/gi, "$1 $2")
 
// eliminating dates and time placed in author parameter
// removing artefacts from Indian news sites (TNN Aug 30, 2012, 05.46AM)
.ohc_regex(/(\|\s*author\s*=\s*(?:[A-Z]{2,3}\b))(?:[^|}]*)\d{4}, [\d\.:]{4,5}(&nbsp;|)[AP]M IST(?=[ ]*\|)/g, "$1$2")
//.ohc_regex(/(\|\s*author=(?:[^\[\]|{}]*))(TNN|PTI) @day @month @yyyy, [\d\.:]{4,5}(&nbsp;|)[AP]M IST(?=[ ]*\|)/g, "$1$2")
 
.ohc_regex(/(\|\s*author\s*=\s*)@month @day,? @yyyy\s?(?:,? [0-2]?\d[\.:][0-5]\d(?:\s*|&nbsp;)(?:[apAP][mM]\s*|)(?:GMT\s*|UTC\s*|[A-Z]{1,2}[DS]T\s*|)|)(?=\|)/g, "$1")
.ohc_regex(/(\|\s*author\s*=\s*)@day @month,? @yyyy\s?(?:,? [0-2]?\d[\.:][0-5]\d(?:\s*|&nbsp;)(?:[apAP][mM]\s*|)(?:GMT\s*|UTC\s*|[A-Z]{1,2}[DS]T\s*|)|)(?=\|)/g, "$1")
.ohc_regex(/(\|\s*author\s*=\s*\w[\w\s]+)@month @day,? @yyyy(?:[^\[\]|{}]*)(?=[|}])/g, "$1")
.ohc_regex(/(\|\s*author\s*=\s*\w[\w\s]+)@day @month,? @yyyy(?:[^\[\]|{}]*)(?=[|}])/g, "$1")
.ohc_regex(/(\|\s*author\s*=\s*(?:\w[\w\s]+)?)@dd-@mm-@yyyy/gi, "$1")
.ohc_regex(/(\|\s*author\s*=\s*(?:\w[\w\s]+)?)@YYYY-@MM-@DD ?/gi, "$1")
.replace(/(\|\s*(?:date|archive-?date|access-?date|author)\s*=\s*(?:\w[\w\s]+)?)[0-2]\d:[0-5]\d(?:[ ]|&nbsp;)?(?:[ap]m|[ap]\.m\.|)(?: ?(?:[A-Z]{1,2}T|UTC)[\.,]?|)/gi, "$1")
//.ohc_regex(/(\|\s*author\s*=\s*(?:\w[\w\s]+)?)\s*[0-2]\d[\.:][0-5]\d(?:[\.:][0-5]\d|)/gi, "$1") //let's see later if we need this
 
// eliminating mm-dd-yyyy dates
.ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)@MM[-–\/\.=\s](1[3-9]|2\d|3[01])[-–\/\.=\s]@YYYY/gi, "$1@Month $2, @YYYY")
.ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)@Mon[-–\/\.=\s](1[3-9]|2\d|3[01])[-–\/\.=\s]@YYYY/gi, "$1@Month $2, @YYYY")
.ohc_regex(/[ ](?:Accessed|Retrieved)(?:(?: online|) on|:?)[ ]@MM[-–\/\.=\s](1[3-9]|2\d|3[01])[-–\/\.=\s]@YYYY(?=\D)/gi, " Retrieved @Month $1, @YYYY")
//.ohc_regex(/[ ](?:Accessed|Retrieved)(?:(?: online|) on|:?)[ ]@YYYY,? @Month @DD(?=\D)/gi, " Retrieved @Day @Month @YYYY")
 
.ohc_regex(/([ =|])@Mon[-–](1[3-9]|2\d|3[01])[-–]@YYYY(?=[^-–\d/])/gi, "$1@Mon $2, @YYYY")
.ohc_regex(/([ =|])@Mon\/(1[3-9]|2\d|3[01])\/@YYYY(?=[^-–\d/])/gi, "$1@Mon $2, @YYYY")
.ohc_regex(/([ =|])@Mon\.(1[3-9]|2\d|3[01])\.@YYYY(?=[^-–\d/])/gi, "$1@Mon $2, @YYYY")
.ohc_regex(/([ =|])@Mon (1[3-9]|2\d|3[01]) @YYYY(?=[^-–\d/])/gi, "$1@Mon $2, @YYYY")
.ohc_regex(/([ =|])@MM[-–](1[3-9]|2\d|3[01])[-–]@YYYY(?=[^-–\d/])/gi, "$1@Mon $2, @YYYY")
.ohc_regex(/([ =|])@MM\/(1[3-9]|2\d|3[01])\/@YYYY(?=[^-–\d/])/gi, "$1@Mon $2, @YYYY")
.ohc_regex(/([ =|])@MM\.(1[3-9]|2\d|3[01])\.@YYYY(?=[^-–\d/])/gi, "$1@Mon $2, @YYYY")
.ohc_regex(/([ =|])@MM (1[3-9]|2\d|3[01]) @YYYY(?=[^-–\d/])/gi, "$1@Mon $2, @YYYY")
 
// eliminating dd-mm-yyyy dates (assumed default)
.ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)@DD[-–\/\.=\s]@MM[-–\/\.=\s]@YYYY/gi, "$1@Day @Month @YYYY")
.ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)@DD[-–\/\.=\s]@Mon[-–\/\.=\s]@YYYY/gi, "$1@Day @Month @YYYY")
.ohc_regex(/[ ](?:Accessed|Retrieved)(?:(?: online|) on|:?)[ ]@DD[-–\/\.=\s]@MM[-–\/\.=\s]@YYYY(?=\D)/gi, " Retrieved @Day @Month @YYYY")
.ohc_regex(/[ ](?:Accessed|Retrieved)(?:(?: online|) on|:?)[ ]@YYYY,? @Month @DD(?=\D)/gi, " Retrieved @Day @Month @YYYY")
.ohc_regex(/([ =|])@DD[-–]@Mon[-–]@YYYY(?=[^-–\d/])/gi, "$1@Day @Month @YYYY")
.ohc_regex(/([ =|])@DD\/@Mon\/@YYYY(?=[^-–\d/])/gi, "$1@Day @Month @YYYY")
.ohc_regex(/([ =|])@DD\.@Mon\.@YYYY(?=[^-–\d/])/gi, "$1@Day @Month @YYYY")
.ohc_regex(/([ =|])@DD @Mon @YYYY(?=[^-–\d/])/gi, "$1@Day @Month @YYYY")
.ohc_regex(/([ =|])@DD[-–]@MM[-–]@YYYY(?=[^-–\d/])/gi, "$1@Day @Month @YYYY")
.ohc_regex(/([ =|])@DD\/@MM\/@YYYY(?=[^-–\d/])/gi, "$1@Day @Month @YYYY")
.ohc_regex(/([ =|])@DD\.@MM\.@YYYY(?=[^-–\d/])/gi, "$1@Day @Month @YYYY")
.ohc_regex(/([ =|])@DD @MM @YYYY(?=[^-–\d/])/gi, "$1@Day @Month @YYYY")
.ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)@DD[-–\/\.=\s]@Month[-–\/\.=\s]@YYNN(?=\s*[|}\n])/gi, "$1@Day @Month @YYYY")
 
//convert yyyy-dd-mm to yyyy-mm-dd
.ohc_regex(/{{(\s*[Cc]it(?:e|ation))([^}]+)(\s*\|\s*(?:publication|archive|access|air|)-?date\s*=\s*(?:1[0-9]|20)\d{2})[-/\.=\s](1[3-9]|2\d|3[01])[-/\.=\s](0?\d|1[0-2])(\s*[\|}<])/gi, "{{$1$2$3-$5-$4$6") // from Batty
 
// eliminating other errant formats
.ohc_regex(/(\|(?:[\w ]*)date\s*=\s*)([0-2]?\d|30|31) @Month \2,? @YYYY(?=\s*[|}])/gi, "$1$2 @Month @YYYY") //repeated digits
.ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)@Day ?@Month ?200([01]\d)[^\s|}]?(?=\s*[|}])/gi, "$1@Day @Month 20$2")
.ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)@Month ?@Day,? ?200([01]\d)[^\s|}]?(?=\s*[|}])/gi, "$1@Month @Day, 20$2")
 
.ohc_regex(/([ ]\()@DD-@MM-@YYYY(\)\W)/gi, "$1@Day @Month @YYYY$2")
.ohc_regex(/([ ]\()@DD-@Month-@YYYY(\)\W)/gi, "$1@Day @Month @YYYY$2")
.ohc_regex(/(\|(?:[\w ]*)date\s*=\s*)@Month, @DD, @YYYY(?=\s*[|}])/gi, "$1@Day @Month @YYYY")
.ohc_regex(/(\|(?:[\w ]*)date\s*=\s*)@DD[\.,] @Month,? @YYYY(?=\s*[|}])/gi, "$1@Day @Month @YYYY")
.ohc_regex(/(\|(?:[\w ]*)date\s*=\s*)@YYYY,? @Month @DD(?=\s*[|}])/gi, "$1@Day @Month @YYYY")
.ohc_regex(/(\|(?:[\w ]*)date\s*=\s*)@YYYY,? @DD @Month(?=\s*[|}])/gi, "$1@Day @Month @YYYY")
.ohc_regex(/[ ]\(@YYYY,? @Month @DD\)/gi, " (@Day @Month @YYYY)")
.ohc_regex(/[ ]\(@YYYY @MM @DD\)/gi, " (@Day @Month @YYYY)")
.ohc_regex(/[ ]\(@YYYY, @DD @Month\)/gi, " (@Day @Month @YYYY)")
.ohc_regex(/(\|(?:[\w ]*)date\s*=\s*)@YYYY,? @Month(?=\s*[|}])/gi, "$1@Month @YYYY")
.ohc_regex(/[ ]\(@YYYY, @Month\)/gi, " (@Month @YYYY)")
.ohc_regex(/[ ]\(@Mon@YYYY\)/gi, " (@Mon @YYYY)")
 
// CS1 errors ISO-like dates (too few or too many digits)
.ohc_regex(/(date\s*=\s*)(?:\[\[)?@YYYY(?:\]\][–—‐]\[\[|[–—‐])@MM[\-–—‐]@DD(?:\]\])?(?=\s*[|}])/gi, "$1@YYYY-@ZM-@ZD") //ndashes and emdashes
.ohc_regex(/(\|\s*access-?date\s*=)\s*@YYYY-0[–—]@DD(?=\s*[|}])/gi, "") //rem nonsense access date
.ohc_regex(/(\|(?:[\w ]*)date\s*=\s*)@YYYY[-–—]@MM[-–—]@DD(?=\s*[|}])/gi, "$1@YYYY-@ZM-@ZD") //ndashes and emdashes
//.ohc_regex(/(\|(?:[\w ]*)date\s*=\s*)@YYYY[\-–—‐]@MM(?=\s*[|}])/gi, "$1@Month @YYYY") //transform "yyyy-mm" to "month year"
.ohc_regex(/(<ref[^>]*>[^<]+?)([\s\(])@YYYY[–—]@MM[–—]@DD([^-\w\/%,<][^<]*?<\/ref>)/gi, "$1$2@Day @Month @YYYY$3")
.ohc_regex(/(<ref[^>]*>[^<]+?)([\s\(])@YYYY[-]@MM[-]([1-9])([^-\w\/%,<][^<]*?<\/ref>)/gi, "$1$2$3 @Month @YYYY$4")
 
// spaces and commas between month and year
.ohc_regex(/@Month(?:,?|\s+of|)(\s|&nbsp;)@YYYY(?=\D)/gi, "@LMonth$1@YYYY")
 
// fix month names (capitalize, remove dots)
.ohc_regex(/(\W)@DD\s@FullMonth(\s+|\s*,)/gi, "$1@Day @FullMonth$2")
.ohc_regex(/(\W)@DD\s@Mon(\s+|\s*,)/gi, "$1@Day @Mon$2")
.ohc_regex(/(\W)@FullMonth\s@DD(\s+|\s*,)/gi, "$1@FullMonth @Day$2")
.ohc_regex(/(\W)@Mon\s@DD(\s+|\s*,)/gi, "$1@Mon @Day$2")
.replace(/(\d(?:st|nd|rd|th) )C(entur(?:ies|y))(?=[ ]*(=|BC|AD|CE))/g, "$1c$2")
//.replace(/(\d(?:st|nd|rd|th) )C(entur(?:ies|y))(?![ \-][A-Z]\w*|''|")/g, "$1c$2")
 
//spaces and commas - in date formats
.ohc_regex(/(\D\W\[?\[?@dd)[ ]+(@month)(\]\])?[ ]*,[ ]*(\[?\[?@yyyy(\sAD|\sBC|\sCE|\sBCE|)\]?\]?\W\D)/gi, "$1 $2$3 $4")
.ohc_regex(/(\D\W\[?\[?)(@month)[ ]+(@dd)(\]?\]?)(?:[ ]*,[ ]*)(\[?\[?@yyyy(\sAD|\sBC|\sCE|\sBCE|)\]?\]?\W\D)/gi, "$1$2 $3$4, $5")
.ohc_regex(/(\D\W\[?\[?)(@month)[ ]+(@dd)(\]?\]?)[ ]+(\[?\[?@yyyy(\sAD|\sBC|\sCE|\sBCE|)\]?\]?\W\D)/gi, "$1$2 $3$4, $5")
 
.ohc_regex(/(@month)(?:, | of )(@yyyy\w)/gi, "$1 $2") //repeat after delinking
 
// spaces and commas - md-md and dm-dm date ranges
.ohc_regex(/(\D\W)@Month\s@DD(&nbsp;|\s)(?:[-–—]|&[mn]dash;)(?:&nbsp;|\s)?@Month\s@DD(?=\W\D)/gi, "$1@LMonth1 @Day1$2– @LMonth2 @Day2")
.ohc_regex(/(\D\W)@Month\s@DD(?:[-–—]|&[mn]dash;)(?:&nbsp;|\s)?@Month\s@DD(?=\W\D)/gi, "$1@LMonth1 @Day1 – @LMonth2 @Day2")
.ohc_regex(/(\D\W)@DD\s@Month(&nbsp;|\s)(?:[-–—]|&[mn]dash;)(?:&nbsp;|\s)?@DD\s@Month(?=\W\D)/gi, "$1@Day1 @LMonth1$2– @Day2 @LMonth2")
.ohc_regex(/(\D\W)@DD\s@Month(?:[-–—]|&[mn]dash;)(?:&nbsp;|\s)?@DD\s@Month(?=\W\D)/gi, "$1@Day1 @LMonth1 – @Day2 @LMonth2")
 
// spaces and commas - d-dm and md-d date ranges
.ohc_regex(/(\D\W)@Month(\s|&nbsp;)@DD@th?(?:(?:\s*|&nbsp;|)[-–](?:\s*|&nbsp;|))@DD@th?(?=\W\D)/gi, "$1@LMonth1$2@Day1–@Day2")
.ohc_regex(/(\D\W)@DD@th?(?:(?:\s*|&nbsp;|)[-–](?:\s*|&nbsp;|))@DD@th?(\s|&nbsp;)@Month(?=\W\D)/gi, "$1@Day1–@Day2$2@LMonth1")
 
// spaces and commas between month and year (again)
.ohc_regex(/@Month(?:,\s+|\s+of\s+)@YYYY(\w)/gi, "@LMonth @YYYY$1");
}
 
/** ------------------------------------------------------------------------- */
function Ohc_UK_slash_dates(){
/// ISO to long format
var txt=document.editform.wpTextbox1;
// resolvable ambiguous date formats
//4-digit year UK style
txt.value=txt.value.replace(/([^\w\d-][0-3]\d)\/0?1\/(\d{4})(?![\w\d-])/g, '$1 January $2');
txt.value=txt.value.replace(/([^\w\d-][0-3]\d)\/0?2\/(\d{4})(?![\w\d-])/g, '$1 February $2');
txt.value=txt.value.replace(/([^\w\d-][0-3]\d)\/0?3\/(\d{4})(?![\w\d-])/g, '$1 March $2');
txt.value=txt.value.replace(/([^\w\d-][0-3]\d)\/0?4\/(\d{4})(?![\w\d-])/g, '$1 April $2');
txt.value=txt.value.replace(/([^\w\d-][0-3]\d)\/0?5\/(\d{4})(?![\w\d-])/g, '$1 May $2');
txt.value=txt.value.replace(/([^\w\d-][0-3]\d)\/0?6\/(\d{4})(?![\w\d-])/g, '$1 June $2');
txt.value=txt.value.replace(/([^\w\d-][0-3]\d)\/0?7\/(\d{4})(?![\w\d-])/g, '$1 July $2');
txt.value=txt.value.replace(/([^\w\d-][0-3]\d)\/0?8\/(\d{4})(?![\w\d-])/g, '$1 August $2');
txt.value=txt.value.replace(/([^\w\d-][0-3]\d)\/0?9\/(\d{4})(?![\w\d-])/g, '$1 September $2');
txt.value=txt.value.replace(/([^\w\d-][0-3]\d)\/10\/(\d{4})(?![\w\d-])/g, '$1 October $2');
txt.value=txt.value.replace(/([^\w\d-][0-3]\d)\/11\/(\d{4})(?![\w\d-])/g, '$1 November $2');
txt.value=txt.value.replace(/([^\w\d-][0-3]\d)\/12\/(\d{4})(?![\w\d-])/g, '$1 December $2');
 
function ohc_ISO_to_dmy_in_citations(editor) {
//2-digit year ('00-'19) UK style
editor
txt.value=txt.value.replace(/([^\w\d-][0-3]\d)\/0?1\/([01]\d)(?![\w\d-])/g, '$1 January 20$2');
// ISO dates within single citation
txt.value=txt.value.replace(/([^\w\d-][0-3]\d)\/0?2\/([01]\d)(?![\w\d-])/g, '$1 February 20$2');
.ohc_regex(/(\|\s*(?:publication|archive|access|air|designation\d?_|)-?date\s*=\s*)@YYYY[-–]@MM[-–]@DD(?=\W\D)/gi, "$1@Day @Month @YYYY"); //regex which converts ymd to dmy or mdy throughout (within citation templates)
txt.value=txt.value.replace(/([^\w\d-][0-3]\d)\/0?3\/([01]\d)(?![\w\d-])/g, '$1 March 20$2');
// .ohc_regex(/(\|\s*(?:publication|)-?date\s*=\s*)@YYYY[-–]@MM[-–]@DD(?=\W\D)/gi, "$1@Day @Month @YYYY");
txt.value=txt.value.replace(/([^\w\d-][0-3]\d)\/0?4\/([01]\d)(?![\w\d-])/g, '$1 April 20$2');
}
txt.value=txt.value.replace(/([^\w\d-][0-3]\d)\/0?5\/([01]\d)(?![\w\d-])/g, '$1 May 20$2');
txt.value=txt.value.replace(/([^\w\d-][0-3]\d)\/0?6\/([01]\d)(?![\w\d-])/g, '$1 June 20$2');
txt.value=txt.value.replace(/([^\w\d-][0-3]\d)\/0?7\/([01]\d)(?![\w\d-])/g, '$1 July 20$2');
txt.value=txt.value.replace(/([^\w\d-][0-3]\d)\/0?8\/([01]\d)(?![\w\d-])/g, '$1 August 20$2');
txt.value=txt.value.replace(/([^\w\d-][0-3]\d)\/0?9\/([01]\d)(?![\w\d-])/g, '$1 September 20$2');
txt.value=txt.value.replace(/([^\w\d-][0-3]\d)\/10\/([01]\d)(?![\w\d-])/g, '$1 October 20$2');
txt.value=txt.value.replace(/([^\w\d-][0-3]\d)\/11\/([01]\d)(?![\w\d-])/g, '$1 November 20$2');
txt.value=txt.value.replace(/([^\w\d-][0-3]\d)\/12\/([01]\d)(?![\w\d-])/g, '$1 December 20$2');
 
function ohc_ISO_to_mdy_in_citations(editor) {
//2-digit year ('60-'99) UK style
editor
txt.value=txt.value.replace(/([^\w\d-][0-3]\d)\/0?1\/([6-9]\d)(?![\w\d-])/g, '$1 January 19$2');
// ISO dates within single citation
txt.value=txt.value.replace(/([^\w\d-][0-3]\d)\/0?2\/([6-9]\d)(?![\w\d-])/g, '$1 February 19$2');
.ohc_regex(/(\|\s*(?:publication|archive|access|air|designation\d?_|)-?date\s*=\s*)@YYYY[-–]@MM[-–]@DD(?=\W\D)/gi, "$1@Month @Day, @YYYY"); //regex which converts ymd to dmy or mdy throughout (within citation templates)
txt.value=txt.value.replace(/([^\w\d-][0-3]\d)\/0?3\/([6-9]\d)(?![\w\d-])/g, '$1 March 19$2');
// .ohc_regex(/(\|\s*(?:publication|)-?date\s*=\s*)@YYYY[-–]@MM[-–]@DD(?=\W\D)/gi, "$1@Month @Day, @YYYY");
txt.value=txt.value.replace(/([^\w\d-][0-3]\d)\/0?4\/([6-9]\d)(?![\w\d-])/g, '$1 April 19$2');
}
txt.value=txt.value.replace(/([^\w\d-][0-3]\d)\/0?5\/([6-9]\d)(?![\w\d-])/g, '$1 May 19$2');
txt.value=txt.value.replace(/([^\w\d-][0-3]\d)\/0?6\/([6-9]\d)(?![\w\d-])/g, '$1 June 19$2');
txt.value=txt.value.replace(/([^\w\d-][0-3]\d)\/0?7\/([6-9]\d)(?![\w\d-])/g, '$1 July 19$2');
txt.value=txt.value.replace(/([^\w\d-][0-3]\d)\/0?8\/([6-9]\d)(?![\w\d-])/g, '$1 August 19$2');
txt.value=txt.value.replace(/([^\w\d-][0-3]\d)\/0?9\/([6-9]\d)(?![\w\d-])/g, '$1 September 19$2');
txt.value=txt.value.replace(/([^\w\d-][0-3]\d)\/10\/([6-9]\d)(?![\w\d-])/g, '$1 October 19$2');
txt.value=txt.value.replace(/([^\w\d-][0-3]\d)\/11\/([6-9]\d)(?![\w\d-])/g, '$1 November 19$2');
txt.value=txt.value.replace(/([^\w\d-][0-3]\d)\/12\/([6-9]\d)(?![\w\d-])/g, '$1 December 19$2');
 
function ohc_ISO_to_dmy_in_references(editor) {
// Add a tag to the summary box
editor
var txt=document.editform.wpSummary;
// multiple calls for multiple dates within single citation
var summary = "resolved [[WP:MOSNUM|slash-dates]]";
.ohc_regex(/(<ref[^>]*>[^<]+?)([\s\(])@YYYY[-–]@MM[-–]@DD([^-\w\/%,<][^<]*?<\/ref>)/gi, "$1$2@Day @Month @YYYY$3")
if (txt.value.indexOf(summary) == -1) {
.ohc_regex(/(<ref[^>]*>[^<]+?)([\s\(])@YYYY[-–]@MM[-–]@DD(<\/ref>)/gi, "$1$2@Day @Month @YYYY$3");
if (txt.value.match(/[^\*\/\s][^\/\s]?\s*$/)) {
txt.value += " | ";
}
txt.value += summary;
}
document.forms.editform.wpMinoredit.checked = true;
// document.editform.wpDiff.click();
}
 
function Ohc_fix_common_errorsohc_ISO_to_mdy_in_references(editor) {
editor
var txt=document.editform.wpTextbox1;
// multiple calls for multiple dates within single citation
.ohc_regex(/(<ref[^>]*>[^<]+?)([\s\(])@YYYY[-–]@MM[-–]@DD([^-\w\/%,<][^<]*?<\/ref>)/gi, "$1$2@Month @Day, @YYYY$3")
.ohc_regex(/(<ref[^>]*>[^<]+?)([\s\(])@YYYY[-–]@MM[-–]@DD(<\/ref>)/gi, "$1$2@Month @Day, @YYYY$3");
}
 
// currently unused
// capitalise month names
function ohc_ISO_to_dmy_anywhere(editor) {
txt.value=txt.value.replace(/(\s)jan(|uary|\.)(\s)/g, '$1Jan$2$3');
editor
txt.value=txt.value.replace(/(\s)feb(|ruary|\.)(\s)/g, '$1Feb$2$3');
// multiple calls for multiple dates within single citation
txt.value=txt.value.replace(/(\d\s)mar(|ch|\.)(\s)/g, '$1Mar$2$3');
.ohc_regex(/([^-\w/])@YYYY[-–]@MM[-–]@DD([^-\w/])/gi, "$1@Day @Month @YYYY$2")
txt.value=txt.value.replace(/(\s)mar(|ch|\.)(\s\d)/g, '$1Mar$2$3');
.ohc_regex(/([^-\w/])@YYYY[-–]@MM[-–]@DD([^-\w/])/gi, "$1@Day @Month @YYYY$2")
txt.value=txt.value.replace(/(\s)apr(|il|\.)(\s)/g, '$1Apr$2$3');
.ohc_regex(/([^-\w/])@YYYY[-–]@MM[-–]@DD([^-\w/])/gi, "$1@Day @Month @YYYY$2");
txt.value=txt.value.replace(/(\d\s)may(,|\.)(\s)/g, '$1May$2$3');
}
txt.value=txt.value.replace(/(\s)may(|\.)(\s\d)/g, '$1May$2$3');
txt.value=txt.value.replace(/(\s)jun(|e|\.)(\s)/g, '$1Jun$2$3');
txt.value=txt.value.replace(/(\s)jul(|y|\.)(\s)/g, '$1Jul$2$3');
txt.value=txt.value.replace(/(\s)aug(|ust|\.)(\s)/g, '$1Aug$2$3');
txt.value=txt.value.replace(/(\s)sep(|tember|\.)(\s)/g, '$1Sep$2$3');
txt.value=txt.value.replace(/(\d{1,2}\s)sept(\s)/g, '$1Sep$2');
txt.value=txt.value.replace(/(\s)oct(|ober|\.)(\s)/g, '$1Oct$2$3');
txt.value=txt.value.replace(/(\s)nov(|ember|\.)(\s)/g, '$1Nov$2$3');
txt.value=txt.value.replace(/(\s)dec(|ember|\.)(\s)/g, '$1Dec$2$3');
 
// currently unused
//underscore in linked dates - dmy
function ohc_ISO_to_mdy_anywhere(editor) {
txt.value=txt.value.replace(/(\[\[[0-3]?\d)_(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))(\]\])/gi, '$1 $2$3');
editor
//underscore in linked dates - mdy
// multiple calls for multiple dates within single citation
txt.value=txt.value.replace(/(\[\[)(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))_([0-3]?\d\]\])/gi, '$1$2 $3');
.ohc_regex(/([^-\w/])@YYYY[-–]@MM[-–]@DD([^-\w/])/gi, "$1@Month @Day, @YYYY$2")
.ohc_regex(/([^-\w/])@YYYY[-–]@MM[-–]@DD([^-\w/])/gi, "$1@Month @Day, @YYYY$2")
.ohc_regex(/([^-\w/])@YYYY[-–]@MM[-–]@DD([^-\w/])/gi, "$1@Month @Day, @YYYY$2");
}
 
function ohc_delink_ISO_to_dmy(editor) {
//remove leading zero from linked date
ohc_ISO_to_dmy_in_citations(editor);
txt.value=txt.value.replace(/(\[\[)(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s0(\d)(?:th|st|nd|rd|)(\]\])/gi, '$1$2 $3$4');
ohc_ISO_to_dmy_in_references(editor);
txt.value=txt.value.replace(/(\[\[)0(\d)(?:th|st|nd|rd|)\s(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))(\]\])/gi, '$1$2 $3$4');
 
editor
//rem redundant spaces (and commas) in date formats
.replace(/([^\w\/\-%,])@YYYY-@MM-@DD(<\s?\/ref.*?>)/g, "$1@Day @Month @Year$2")
txt.value=txt.value.replace(/([^\d][^\w\d]\[?\[?[0-3]?\d)[ ]+(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))(\]\])?[ ]*,[ ]*(\[?\[?\d{3,4}(\sAD|\sBC|\sCE|\sBCE|)\]?\]?[^\w\d][^\d])/gi, '$1 $2$3 $4');
.ohc_regex(/(\|\|[ ]*)@YYYY[-–]@MM[-–]@DD([ ]*\|\|)/gi, "$1{{dts|format=dmy|@YYYY|@MM|@DD}}$2") // dts template for sortable tables
txt.value=txt.value.replace(/([^\d][^\w\d]\[?\[?)(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))[ ]+([0-2]?\d|30|31)(\]?\]?)(?:[ ]*,[ ]*)(\[?\[?\d{3,4}(\sAD|\sBC|\sCE|\sBCE|)\]?\]?[^\w\d][^\d])/gi, '$1$2 $3$4, $5');
.ohc_regex(/(\{\{dts\|format=)mdy\|/gi, "$1dmy|"); //flip dts template formats
txt.value=txt.value.replace(/([^\d][^\w\d]\[?\[?)(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))[ ]+([0-2]?\d|30|31)(\]?\]?)[ ]+(\[?\[?\d{3,4}(\sAD|\sBC|\sCE|\sBCE|)\]?\]?[^\w\d][^\d])/gi, '$1$2 $3$4, $5');
}
 
function ohc_delink_ISO_to_mdy(editor) {
txt.value=txt.value.replace(/(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))(?:, | of )(\d{3,4}[\w\d])/gi, '$1 $2'); //repeat after delinking
ohc_ISO_to_mdy_in_citations(editor);
ohc_ISO_to_mdy_in_references(editor);
 
editor
Ohc_protect_dates_in_titles();
.replace(/([^\w\/\-%,])@YYYY-@MM-@DD(<\s?\/ref.*?>)/g, "$1@Month @Day, @Year$2")
//remove unlinked ordinal date formats
.ohc_regex(/(\|\|[ ]*)@YYYY[-–]@MM[-–]@DD([ ]*\|\|)/gi, "$1{{dts|@YYYY|@MM|@DD}}$2") // dts template for sortable tables (mdy is default)
txt.value=txt.value.replace(/(?:the\s?)?([1-3]?\d)(?:th|st|nd|rd|), ([1-3]?\d)(?:th|st|nd|rd|)(\s(?:and|&|to|or)\s[1-3]?\d)(?:th|st|nd|rd|)(?:\sof\s?)?\s(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))([^\w\d])/gi, '$1, $2$3 $4 $5');
.ohc_regex(/(\{\{dts\|)format=(?:mdy|dmy|) ?\|/gi, "$1"); // flip dts template formats
txt.value=txt.value.replace(/(?:the\s?)?([1-3]?\d)(?:th|st|nd|rd|)(\s(?:and|&|to|or)\s[1-3]?\d)(?:th|st|nd|rd|)(?:\sof\s?)?\s(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))([^\w\d])/gi, '$1$2 $3$4');
}
txt.value=txt.value.replace(/(?:the\s?)?([1-3]?\d)(?:th|st|nd|rd|)(?:\sof\s?)\s(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))([^\|\]\w\d])/gi, '$1 $2$3');
txt.value=txt.value.replace(/(?:the\s?)?([1-3]?\d)(?:th|st|nd|rd|)(?:\sof\s?)?\s(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))([^\w\d])/gi, '$1 $2$3');
txt.value=txt.value.replace(/(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s(?:the\s)?([1-3]?\d)(?:th|st|nd|rd|),\s(?:the\s)?([1-3]?\d)(?:th|st|nd|rd|)(\s(?:and|&|to|or)\s)(?:the\s)?([1-3]?\d)(?:th|st|nd|rd|)([^\]\|\w\d][^\d])/gi, '$1 $2, $3$4 $5$6');
txt.value=txt.value.replace(/(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s(?:the\s)?([1-3]?\d)(?:th|st|nd|rd|)(\s(?:and|&|to|or)\s)(?:the\s)?([1-3]?\d)(?:th|st|nd|rd|)([^\]\|\w\d][^\d])/gi, '$1 $2$3$4$5');
txt.value=txt.value.replace(/(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s(?:the\s)?([1-3]?\d)(?:th|st|nd|rd)([^\]\|\w\d][^\d])/gi, '$1 $2$3');
 
function ohc_delink_year_in_X(editor) {
//fix 'bda' template redirect
editor
txt.value=txt.value.replace(/{{bda\|([^}]+)}}/gi, '{{birth date and age|$1}}');
//.ohc_regex(/\{\{(?:avyear|by|baseball\syear|fy|ly|mlby|mlb\syear|scy|sdy)\|(@year)\}\}/gi, "$1") // disabled 3/5/21 discussion at https://en.wikipedia.org/w/index.php?title=Wikipedia_talk:WikiProject_Baseball&oldid=1021203365#Links_to_baseball_year_articles_in_infobox?
//.ohc_regex(/\{\{(?:avyear|by|baseball\syear|fy|ly|mlby|mlb\syear|scy|sdy)\|@year\|(@year)\}\}/gi, "$1")
.ohc_regex(/\[\[@yyyy\sin\s[^|\]]+\|((?:(?:@day |)@month |)@yyyy)\]\]/gi, "$1")
.replace(/\[\[(?:\d{4}[-–]\d{2} in English football)\|((?:(?:@Day |)@Month |)@YYYY)\]\]/gi, "$1")
 
.replace(/\[\[\d{4} Major League Baseball season\|(\d{4})(\sseason)?\]\]/gi, "$1$2");
//zap redundant templates ('date', 'as of', 'English', '#dateformat:')
}
txt.value=txt.value.replace(/\{\{date\|([^\}\|]+)(?:[^\}]+)?\}\}/gi, '$1');
txt.value=txt.value.replace(/{{#dateformat:([^\}\|]+)(?:\|dmy|\|mdy)?}}/gi,'$1');
 
 
// format parameter must be 'dmy' or 'mdy'
function ohc_fix_dts_template(editor, format) {
editor
// dts - format=dmy in this case (per D12000)
// per {{dts}} doc, remove the obsolete link=off param
.replace(/(\{\{dts[^}]*)(?:\|link=off)/gi, "$1")
.ohc_regex(/(\{\{dts\s*\|\s*@year\s*\|\s*@month\s*\|\s*@day\s*\|\s*format=)(?:dmy|mdy)(\}\})/gi, "$1"+format+"$2")
.ohc_regex(/(\{\{dts\s*\|\s*format=)(?:dmy|mdy)(\s*\|\s*@year\s*\|\s*@month\s*\|\s*@day\s*\}\})/gi, "$1"+format+"$2")
.ohc_regex(/(\{\{dts\s*\|\s*@year\s*\|\s*@month\s*\|\s*@day\s*)(\}\})/gi, "$1|format="+format+"$2")
 
// stripping – {{dts}} serves no purpose inside date parameters
.ohc_regex(/(\|(?:[\w ]*)date\s*=\s*)\{\{dts\s*\|\s*format=(?:dmy|mdy)\s*\|\s*([|}]*)\}\}(?=\s*[|}])/gi, "$1$2")
.ohc_regex(/(\|(?:[\w ]*)date\s*=\s*)\{\{dts\s*\|\s*([|}]*)(?:\|\s*format=(?:dmy|mdy)\s*|)\}\}(?=\s*[|}])/gi, "$1$2")
.ohc_regex(/(\|(?:[\w ]*)date\s*=\s*)\{\{dts\s*\|\s*format=(?:dmy|mdy)\s*\|\s*@YYYY(\s*\|\s*|-)@MM(\s*\|\s*|-)@DD\s*\}\}(?=\s*[|}])/gi, "$1@YYYY-@MM-@DD ")
.ohc_regex(/(\|(?:[\w ]*)date\s*=\s*)\{\{dts\s*\|\s*@YYYY(\s*\|\s*|-)@MM(\s*\|\s*|-)@DD\s*\|\s*format=(?:dmy|mdy)\s*\}\}(?=\s*[|}])/gi, "$1@YYYY-@MM-@DD ");
}
 
// format parameter must be 'dmy' or 'mdy'
function Ohc_protect_dates_in_titles(){
function ohc_fix_gr_template(editor, format) {
var txt=document.editform.wpTextbox1;
editor
// GR - date formatting parameter
// per {GR} doc, insert date formatting param
.replace(/(\{\{GR\|\d\d?)(?!\|date)/gi, "$1|dateform=" + format);
}
 
function ohc_dates_to_dmy(editor) {
editor
.replace(/\|df=[mdy]{3}(?:-all|)(?=\s*[|}])/gi, '')
.replace(/\|format=mdy/gi, "|format=dmy")
 
// change start and end templates; vgrelease new v=2 or mdy is default
.replace(/(\{\{(?:start date|end date)[^|}]*\|)df=ye?s?\|([^}]*df=ye?s?)/gi, "$1$2")
.replace(/(\{\{vgrelease new[^|}]*\|)(?:v=1\||)([A-Z]{2,3}\|)/g, "$1v=2|$2")
.ohc_regex(/(\|\s*(?:begin|end|first|last)\s*=\s*)@YYYY[-–]@MM[-–]@DD(?=\W\D)/gi, "$1@Day @Month @YYYY") // spotted at [[Template:Infobox recurring event]]
 
// change birth and death templates
.replace(/(\{\{(?:(?:Birth|Death|Disappeared) date(?: and (?:given |)age|)|launch|release|start)[^}]*\|)m(f=ye?s?)/gi, "$1d$2") // substitute df for mf
.replace(/(\{\{(?:(?:Birth|Death|Disappeared) date(?: and (?:given |)age|)|launch|release|start|film ?date|Wayback)[\|\d]+)(\}\})/gi, "$1|df=y$2") // insert df parameter
.replace(/(\{\{(?:(?:Birth|Death|Disappeared) date(?: and (?:given |)age|)|launch|release|start|film ?date|Wayback)[\|\d]+\|)df=ye?s?\|([^}]*df=ye?s?)/gi, "$1$2") // put date format parameter at the end
.replace(/(\{\{(?:start date|end date)\|)df=ye?s?\|((?:1[789]|20)\d{2}\}\})/gi, "$1$2") // date format parameter not needed – year only
 
// convert date ranges (md,d,d-dy to d,d,d-dmy; md,d,d-d to d,d,d-dm; md,d,d to d,d,dm)
.ohc_regex(/(\D\W)@Month((?:\s@day?,?){1,6}),?(\/|\s?(?:[-–]|&ndash;)\s?|(?:[ _]|&nbsp;)(?:and|&|to|or)(?:[ _]|&nbsp;)+?)@Day,?\s(?:of\s)?(@yyyy\W\D)/gi, "$1$2$3@Day @LMonth $4")
.ohc_regex(/(\D\W)@Month((?:\s@day?,?){1,6}),?(\/|\s?(?:[-–]|&ndash;)\s?|(?:[ _]|&nbsp;)(?:and|&|to|or)(?:[ _]|&nbsp;)+?)@Day(?=\W\D)/gi, "$1$2$3@Day @LMonth")
 
//.ohc_regex(/(\D\W)@Month((?:\s@day?,?){1,6}) @Day(?=\W\D)/gi, "$1$2 @Day @LMonth") //disabling as unlikely and ungrammatical constructions causing false positives
 
//'md, md,' to 'dm, dm,'
.ohc_regex(/(\D\W)@Month @Day, @Month @Day(?=[,\.]\W\D)/gi, "$1@Day1 @LMonth1, @Day2 @LMonth2")
 
//permanentconvert protectionsimple for dmymdy dates withinto imagesdmy
.ohc_regex(/(p(?:g?\.?|age) ?\d+|p(?:p\.?|ages) ?\d+[-–]\d+), @Month((?:\s@day?,?){1,6}) @Day(?=\W\D)/gi, "$1. $2 @Day @LMonth")
txt.value=txt.value.replace(/((?:file|image|img)[\s]*[:=][^\|]{1,30})\s([0-2]?\d|30|31)(th|st|nd|rd|)(\sof)?\s(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))(,)?(\s(?:[12]?\d{3}))?/gi, '$1_$2$3$4_$5$6$7');
.ohc_regex(/(\D\W)@Month\s@Day,?\s@Year(\s?(?:AD|BC|CE|BCE)\W\D)/gi, "$1@Day @LMonth @Year$2")
txt.value=txt.value.replace(/(\((?:file|image|img)[\s]*[:=][0-3]?\d)(th|st|nd|rd|)(\sof)?\s(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))(,)?(\s(?:[12]?\d{3}))?/gi, '$1$2$3_$4$5_$6$7');
.ohc_regex(/(\|\s*term_(?:end|start)\d\s*=\s*|\D\W)@Month\s@Day,?\s@YYYY(?=\W\D)/gi, "$1@Day @LMonth @Year")
.ohc_regex(/(\|\s*term_(?:end|start)\d\s*=\s*|\D\W)@Month\s@Day(?=\W\D)/gi, "$1@Day @LMonth")
 
//Month+day_number " 7th March" -> "7 March"
txt.value=txt.value.replace(/([0-2]?\d|30|31)(th|st|nd|rd|)(\sof)?\s(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))(,)?\s([12]\d{3})(\.jpe?g)/gi, '$1$2$3_$4$5_$6$7');
.ohc_regex(/(\D\W)@Day\s@Month\s@YYYY(?=\W\D)/gi, "$1@Day @LMonth @Year")
txt.value=txt.value.replace(/([0-2]?\d|30|31)(th|st|nd|rd|)(\sof)?\s(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))(\.jpe?g)/gi, '$1$2$3_$4$5');
.ohc_regex(/(\D\W)@Day\s@Month(?=\W\D)/gi, "$1@Day @LMonth")
.ohc_regex(/(\D\W)@Month\s@Day,?\s@Year(?=\W\D)/gi, "$1@Day @LMonth @Year")
 
//dates with embedded nbsp
//protect dmy date formats within titles of citation templates
.ohc_regex(/(\D\W)@Month([ _]|&nbsp;)(\d{1,2},(?: |&nbsp;)\d{1,2}(?:\s(?:and|&|to|or)(?:[ _]|&nbsp;))\d{1,2})(?=[^|\]\w])/gi, "$1$3$2@LMonth ")
txt.value=txt.value.replace(/(\|[ ]*(?:title|work|quote)[ ]*=[^\|]*)((?:[0-3]?\d)(?:th|st|nd|rd|),?(?:\sof)?)\s(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))([^\|]{0,30}\|)/gi, '$1$2&nbsp;$3$4');
.ohc_regex(/(\D\W)@Month([ _]|&nbsp;|{{(?:break|nbsp)}})@Day,([ _]|&nbsp;|{{(?:break|nbsp)}})@YYYY(?=[^|\]\w])/gi, "$1@Day$2@Month$3@Year")
//blockquotes
txt.value=txt.value.replace(/(<blockquote>[^<]+?)((?:[0-3]?\d)(?:th|st|nd|rd|),?(?:\sof)?)\s(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))(,)?\s?(\d{1,4})?([^<]+?<\/blockquote>)/g, '$1$2&nbsp;$3$4');
 
//remove comma
.ohc_regex(/(\D\W)@Day\s@Month,\s?@Year(?=\W\D)/gi, "$1@Day @LMonth @Year")
//permanent protection for mdy dates within images
txt.value=txt.value.replace(/((?:file|image|img)[\s]*[:=][^\|]{1,60})\s(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))(\sthe)?\s([0-2]?\d|30|31)(th|st|nd|rd|)(,)?(\s(?:[12]?\d{3}))?/gi, '$1_$2$3_$4$5$6$7');
txt.value=txt.value.replace(/((?:file|image|img)[\s]*[:=])(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))(\sthe)?\s([0-2]?\d|30|31)(th|st|nd|rd|)(,)?(\s(?:[12]?\d{3}))?/gi, '$1$2$3_$4$5$6$7'); //re-enabled 13 Aug 2010
txt.value=txt.value.replace(/(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))(\sthe)?\s([0-2]?\d|30|31)(th|st|nd|rd|)(,)?\s([12]\d{3})(\.(?:png|jpe?g))/gi, '$1$2_$3$4$5_$6$7');
txt.value=txt.value.replace(/(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))(\sthe)?\s([0-2]?\d|30|31)(th|st|nd|rd|)(\.png|\.jpe?g)/gi, '$1$2_$3$4$5');
 
// remove "the" from "on the dd month"
//protect mdy date formats within titles of citation templates
.ohc_regex(/(on |by )the @Day\s@Month(?=[ ,\)\.])/gi, "$1@Day @LMonth")
txt.value=txt.value.replace(/(\|[ ]*(?:title|work|quote|chapter)[ ]*=[^\|]+?)([^\d][^\w\d])(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))(\sthe)?\s((?:[0-3]?\d)(?:th|st|nd|rd|))([^\w\d])/gi, '$1$2$3$4&nbsp;$5$6');
//blockquotes
txt.value=txt.value.replace(/(<blockquote>[^<]+?)([^\d][^\w\d])(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))(\sthe)?\s((?:[0-3]?\d)(?:th|st|nd|rd|),?)\s(\d{1,4})([^<]+?<\/blockquote>)/g, '$1$2$3$4&nbsp;$5&nbsp;$6$7');
 
//remove space from date range conversion
.ohc_regex(/(\D ) @Day(\/|\s?(?:[-–]|&ndash;)\s?|(?:[ _]|&nbsp;)(?:and|&|to|or)(?:[ _]|&nbsp;)+?)/gi, "$1@Day$2");
}
 
function ohc_dates_to_mdy(editor) {
editor
// change birth and death templates – mf=y is the default; vgrelease new v=2 or mdy is default
.replace(/\|df=[mdy]{3}(?:-all|)(?=\s*[|}])/gi, '')
.replace(/\|df=y(?:es|)(?=[|}\s])/gi, '')
.replace(/(mf=y(?:es|)\|[^}]*\|)(?:mf=y(?:es|)\|)/gi, "$1")
.replace(/(\{\{vgrelease new[^|}]*\|)(?:v=2\||)([A-Z]{2,3}\|)/g, "$1$2")
.ohc_regex(/(\|\s*(?:begin|end|first|last)\s*=\s*)@YYYY[-–]@MM[-–]@DD(?=\W\D)/gi, "$1@Month @Day, @YYYY")
 
// convert date ranges (d,d,d-dmy to md,d,d-dy; d,d,d-dm to md,d,d-d; dm,d,d to md,d,d)
function Ohc_code_delink_dates() {
.ohc_regex(/(\D\W)@Day((?:, @day){0,5})(\/|\s?(?:[-–]|&ndash;)\s?|\s(?:and|&|to|or)\s+?)@Day\s@Month,? @YYYY(?=\W\D)/gi, "$1@LMonth @Day1$2$3@Day2, @YYYY")
var txt=document.editform.wpTextbox1;
.ohc_regex(/(\D\W)@Day((?:, @day){0,5})(\/|\s?(?:[-–]|&ndash;)\s?|\s(?:and|&|to|or)\s+?)@Day\s@Month(?=\W\D)/gi, "$1@LMonth @Day1$2$3@Day2")
Ohc_protect_dates ();
//.ohc_regex(/(\D\W)@Day((?:, @day){0,5})\s@Month,? @YYYY(?=\W\D)/gi, "$1@LMonth @Day1$2, @YYYY") // disabling as unlikely and ungrammatical constructions causing false positives
Ohc_fix_common_errors();
//.ohc_regex(/(\D\W)@Day((?:, @day){0,5})\s@Month(?=\W\D)/gi, "$1@LMonth @Day1$2") // disabling as unlikely and ungrammatical constructions causing false positives
//delink ISO8601 dates
txt.value=txt.value.replace(/\[\[(\d{4}-[0-1]\d-[0-3]\d)\]\]/gi, '$1');
txt.value=txt.value.replace(/\[\[(\d{4})\]\]-\[\[([0-1]\d-[0-3]\d)\]\]/gi, '$1-$2');
txt.value=txt.value.replace(/(\d{4})-\[\[([0-1]\d-[0-3]\d)\]\]/gi, '$1-$2');
txt.value=txt.value.replace(/\[\[(\d{4})\]\]-([0-1]\d-[0-3]\d)/gi, '$1-$2');
 
// 'dm, dm,' to 'md, md,'
//delink full dates - dmy
.ohc_regex(/(\D\W)@Day @Month, @Day @Month(?=[,\.]?\W\D)/gi, "$1@LMonth1 @Day1, @LMonth2 @Day2")
txt.value=txt.value.replace(/(?:the\s)?\[\[([1-3]?\d)(?:th|st|nd|rd|)[\s_](?:of[\s_])?(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.?|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\]\]/gi, '$1 $2');
 
// convert simple dmy dates to mdy
//delink single md or 'm the dth'
.ohc_regex(/(p(?:g?\.?|age) ?\d+|p(?:p\.?|ages) ?\d+[-–]\d+), @Month((?:\s@day?,?){1,6}) @Day(?=\W\D)/gi, "$1. @LMonth $2 @Day")
txt.value=txt.value.replace(/\[\[(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.?|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))[\s_](?:the[\s_])?([1-3]?\d)(?:th|st|nd|rd|)\]\]([^\w\d])/gi, '$1 $2$3');
.ohc_regex(/(\D\W)@Day(\s|&nbsp;)@Month,?(\s|&nbsp;)@Year(?=\W\D)/gi, "$1@LMonth$2@Day,$3@Year")
.ohc_regex(/(\|\s*term_(?:end|start)\d\s*=\s*|\D\W)@Day[ ]+@Month,?\s@YYYY(?=\W\D)/gi, "$1@LMonth @Day, @Year")
.ohc_regex(/(\|\s*term_(?:end|start)\d\s*=\s*|\D\W)@Day[ ]+@Month(?=\W\D)/gi, "$1@LMonth @Day")
 
// Month+day_number "[[March 7]]th7th" -> "March 7"
.ohc_regex(/(\D\W)@Month\s@Day@th?,?\s@YYYY(?=\W\D)/gi, "$1@LMonth @Day, @YYYY")
txt.value=txt.value.replace(/\[\[((?:Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.?|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s[1-3]?\d)\]\](?:th|st|nd|rd)/gi, '$1');
.ohc_regex(/(\D\W)@Day@th?(\s|&nbsp;)@Month(\s|&nbsp;)@YYYY(?=\W\D)/gi, "$1@LMonth$2@Day,$3@YYYY")
.ohc_regex(/(\D\W)@Month(\s|&nbsp;)@Day(?=\W\D)/gi, "$1@LMonth$2@Day")
.ohc_regex(/(\D\W)@Day@th?(\s|&nbsp;)@Month([,\.])(?=\W\D)/gi, "$1@LMonth$2@Day$3")
 
// add comma where missing
//removal of 'year in foo' in full dates (with or without links) with incorrect '[[year in foo|YYYY]]'
.ohc_regex(/(\D\W)@Month\s@Day,?\s@YYYY,?(?=\s\w)/gi, "$1@LMonth @Day, @YYYY,")
txt.value=txt.value.replace(/(\[?\[?(?:Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.?|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s(?:[0-3][\d]|[\d])\]?\]?),\s\[\[(\d{1,4})\sin\s[^\]]{1,32}\]\]/gi, '$1 $2');
txt.value=txt.value.replace(/(\[?\[?(?:Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.?|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s(?:[0-3][\d]|[\d])\]?\]?),\s{{(?:avyear|by|fy|ly|mlb|scy|sdy)\|(\d{1,4})}}/gi, '$1 $2');
txt.value=txt.value.replace(/(\[?\[?(?:[0-3][\d]|[\d])\s(?:Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.?|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\]?\]?)\s\[\[(\d{1,4})\sin\s[^\]]{1,32}\]\]/gi, '$1 $2');
txt.value=txt.value.replace(/(\[?\[?(?:[0-3][\d]|[\d])\s(?:Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.?|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\]?\]?)\s{{(?:avyear|by|fy|ly|mlb|scy|sdy)\|(\d{1,4})}}/gi, '$1 $2');
 
// rem superfluous comma where applicable
//month+day+year piped pseudo-ISO dates
.ohc_regex(/(\D[^\w\/])@Month\s@ZD,,(?=\W\D|\b)/gi, "$1@LMonth @Day,");
txt.value=txt.value.replace(/\[\[(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.?|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))( [0-2]?\d|30|31)\|[0-3]?\d-[0-3]?\d\]\]-(?:\[\[)?([1-2]\d\d\d)(\|\d{2,4})?(?:\]\])?/gi, '$1$2, $3');
}
txt.value=txt.value.replace(/\[\[([0-3]\d\s(?:Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.?|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|)))\|[0-3]?\d-[0-3]?\d\]\]-(?:\[\[)?([1-2]\d{3})(\]\])?/gi, '$1 $2');
 
function ohc_fix_dmy_redundancies(editor) {
//month+day piped
editor
txt.value=txt.value.replace(/(?:the\s)?\[\[\d{1,2}(?:th|st|nd|rd|)[\s_](?:of[\s_])?(?:Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.?|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\|([^\]]{1,30})\]\]/gi, '$1');
// month-range redundancies (repeating month names)
.ohc_regex(/([\D]@dd)@th? @Month[ ]{1,2}((?:to|and|-|–)[ ]{1,2}@dd)@th? @Month/, "$1 $2 @LMonth", function(d1, d2) {
if (d1.m == d2.m) return true;
return false;
});
}
 
function ohc_fix_mdy_redundancies(editor) {
//'[[month day|xxXxx]]Xyyyy ' to 'month day, year'
editor
txt.value=txt.value.replace(/\[\[(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.?|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s(\d{1,2})(?:th|st|nd|rd|)\|\d?\d\.\d?\d\]\].(\d{3,4})/gi, '$1 $2, $3');
//'[[day month|xxXxx]]Xyyyy'-range toredundancies 'day(repeating month year'names)
.ohc_regex(/(@Month[ ]{1,2}@dd)@th? (to|and|-|–)[ ]{1,2}@Month[ ]{1,2}@DD@th?/, "$1 $2 @LDay", function(d1, d2) {
txt.value=txt.value.replace(/\[\[(\d{1,2})(?:th|st|nd|rd|)\s(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.?|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\|\d?\d\.\d?\d\]\].(\d{3,4})/gi, '$1 $2 $3');
if (d1.m == d2.m) return true;
return false;
});
}
 
function ohc_expand_ref_dates(editor) {
// century
editor
txt.value=txt.value.replace(/\[\[((?: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|centuries)(\sAD|\sBC|\sCE|\sBCE|)\]\]/gi, '$1$2$3');
.ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)@Month @YYYY(?=\s*[|}])/gi, "$1@FullMonth @YYYY")
txt.value=txt.value.replace(/\[\[(?: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|centuries)(?:\sAD|\sBC|\sCE|\sBCE|)\|([^\]]{1,30})\]\]/gi, '$1');
.ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)@Day @Month @YYYY(?=\s*[|}])/gi, "$1@Day @FullMonth @YYYY")
txt.value=txt.value.replace(/\[\[(\d{1,2}(?:st|nd|rd|th)[\s-_])(century|centuries)(\sAD|\sBC|\sCE|\sBCE|)\]\]/gi, '$1$2$3');
.ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)@Month @Day, @YYYY(?=\s*[|}])/gi, "$1@FullMonth @Day, @YYYY")
txt.value=txt.value.replace(/\[\[\d{1,2}(?:st|nd|rd|th)[\s-_](?:century|centuries)(?:\sAD|\sBC|\sCE|\sBCE|)\|([^\]]{1,30})\]\]/gi, '$1');
 
.ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)((?:[01-2]?\d|30|31) |)@Month @YYYY ?(?:-|–|&ndash;) ?((?:[01-3]?\d|30|31) |)@Month @YYYY(?=\s*[|}])/gi, "$1$2 @FullMonth1 @YYYY1 – $3@FullMonth2 @YYYY2")
// months
.ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)@Month @Day(, (?:19|20)\d\d) ?(?:-|–|&ndash;) ?@Month @Day, @YYYY(?=\s*[|}])/gi, "$1@FullMonth1 @Day1$2 – @FullMonth2 @Day2, @YYYY")
txt.value=txt.value.replace(/\[\[(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.?|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\]\]/gi, '$1');
.ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)@Day @Month,?( (?:19|20)\d\d) ?(?:-|–|&ndash;) ?@Day @Month @YYYY(?=\s*[|}])/gi, "$1@Day1 @FullMonth1$2 – @Day2 @FullMonth2 @YYYY")
txt.value=txt.value.replace(/\[\[(?:January|February|March|April|May|June|July|August|September|October|November|December)\|([^\]]{1,30})\]\]/gi, '$1');
.ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)@Month,?( (?:19|20)\d\d) ?(?:-|–|&ndash;) ?@Month,? @YYYY(?=\s*[|}])/gi, "$1@FullMonth1$2 – @FullMonth2 @YYYY")
.ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)((?:19|20)\d\d) ?(?:-|–|&ndash;) ?@Month @YYYY(?=\s*[|}])/gi, "$1@$2 – @FullMonth @YYYY")
 
.ohc_regex(/(<ref[^>]*>(?:[^<]+?[\s\(]|))((?:[01-2]?\d|30|31) |)@Month @YYYY ?(?:-|–|&ndash;) ?((?:[01-3]?\d|30|31) |)@Month @YYYY(?=(?:[^-\w\/%,<][^<]*?|)<\/ref>)/gi, "$1$2@FullMonth1 @YYYY1 – $3@FullMonth2 @YYYY2")
// decades and years
.ohc_regex(/(<ref[^>]*>(?:[^<]+?[\s\(]|))@Month @Day(, (?:19|20)\d\d) ?(?:-|–|&ndash;) ?@Month @Day, @YYYY(?=(?:[^-\w\/%,<][^<]*?|)<\/ref>)/gi, "$1@FullMonth1 @Day1$2 – @FullMonth2 @Day2, @YYYY")
txt.value=txt.value.replace(/\[\[(\d{1,3}0)\'?s\]\]/g, '$1s');
.ohc_regex(/(<ref[^>]*>(?:[^<]+?[\s\(]|))@Day @Month,?( (?:19|20)\d\d) ?(?:-|–|&ndash;) ?@Day @Month @YYYY(?=(?:[^-\w\/%,<][^<]*?|)<\/ref>)/gi, "$1@Day1 @FullMonth1$2 – @Day2 @FullMonth2 @YYYY")
txt.value=txt.value.replace(/\[\[\d{1,3}0\'?s?\|([^\]]{1,30})\]\]/g, '$1');
.ohc_regex(/(<ref[^>]*>(?:[^<]+?[\s\(]|))@Month,?( (?:19|20)\d\d) ?(?:-|–|&ndash;) ?@Month,? @YYYY(?=(?:[^-\w\/%,<][^<]*?|)<\/ref>)/gi, "$1@FullMonth1$2 – @FullMonth2 @YYYY")
txt.value=txt.value.replace(/\[\[(\d{1,3}0)\'?(s)?\s(AD|BC|CE|BCE)\]\]/gi, '$1$2 $3');
.ohc_regex(/(<ref[^>]*>(?:[^<]+?[\s\(]|))((?:19|20)\d\d) ?(?:-|–|&ndash;) ?@Month @YYYY(?=(?:[^-\w\/%,<][^<]*?|)<\/ref>)/gi, "$1$2 – @FullMonth @YYYY");
txt.value=txt.value.replace(/\[\[(\d{1,4}[\s_]?)(AD|BC|CE|BCE|)\]\]/gi, '$1$2');
}
txt.value=txt.value.replace(/\[\[(AD|BC|CE|BCE|)([\s_]?)(\d{1,4})\]\]/gi, '$3$2$1');
txt.value=txt.value.replace(/\[\[\d{1,3}0\'?s?\s(?:AD|BC|CE|BCE)\|([^\]]{1,30})\]\]/gi, '$1');
txt.value=txt.value.replace(/\[\[\d{1,3}0\'?s?\s\(decade\)\|([^\]]{1,30})\]\]/gi, '$1');
 
function ohc_expand_all_dates(editor) {
//month+year
editor
//Identify surprise or 'Easter egg' diversions linking month+years to year articles. Turn them into month+year links to be dealt with below
.ohc_regex(/([^-\w/])@Month @YYYY(?=[^-\w/])/gi, "$1@FullMonth @YYYY")
txt.value=txt.value.replace(/\[\[\d{1,4}#[^\|\]]+\|((?:Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.?|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s\d{3,4})\]\]/gi, '$1');
.ohc_regex(/([^-\w/])@Day @Month @YYYY(?=[^-\w/])/gi, "$1@Day @FullMonth @YYYY")
txt.value=txt.value.replace(/\[\[((?:Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.?|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s\d{3,4})\]\]/gi, '$1');
.ohc_regex(/([^-\w/])@Month @Day, @YYYY(?=[^-\w/])/gi, "$1@FullMonth @Day, @YYYY")
txt.value=txt.value.replace(/\[\[(?:Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.?|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s\d{3,4}\|([^\]]{1,30})\]\]/gi, '$1');
 
.ohc_regex(/([^-\w/])((?:[01-2]?\d|30|31) |)@Month @YYYY ?(?:-|–|&ndash;) ?((?:[01-3]?\d|30|31) |)@Month @YYYY(?=[^-\w/])/gi, "$1$2@FullMonth1 @YYYY1 – $3@FullMonth2 @YYYY2")
//removed piped years when in full date
.ohc_regex(/([^-\w/])@Month @Day(, (?:19|20)\d\d) ?(?:-|–|&ndash;) ?@Month @Day, @YYYY(?=[^-\w/])/gi, "$1@FullMonth1 @Day1$2 – @FullMonth2 @Day2, @YYYY")
txt.value=txt.value.replace(/(\[\[\d{1,2}\s(?:Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.?|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\]\],?\s?\[\[)[^\|\]]{1,32}\|(\d{1,4}\]\])/gi, '$1$2');
.ohc_regex(/([^-\w/])@Day @Month,?( (?:19|20)\d\d) ?(?:-|–|&ndash;) ?@Day @Month @YYYY(?=[^-\w/])/gi, "$1@Day1 @FullMonth1$2 – @Day2 @FullMonth2 @YYYY")
txt.value=txt.value.replace(/(\[\[(?:Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.?|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s\d{1,2}\]\],?\s?\[\[)[^\|\]]{1,32}\|(\d{1,4}\]\])/gi, '$1$2');
.ohc_regex(/([^-\w/])@Month,?( (?:19|20)\d\d) ?(?:-|–|&ndash;) ?@Month,? @YYYY(?=[^-\w/])/gi, "$1@FullMonth1$2 – @FullMonth2 @YYYY")
.ohc_regex(/([^-\w/])((?:19|20)\d\d) ?(?:-|–|&ndash;) ?@Month @YYYY(?=[^-\w/])/gi, "$1$2 – @FullMonth @YYYY")
 
.ohc_regex(/([ ]\(|\|\s*)@Day @Month @YYYY(?=\)\W|\s*[|\n])/gi, "$1@Day @FullMonth @YYYY")
//Identify surprise or 'Easter egg' diversions linking months to year articles.
.ohc_regex(/([ ]\(|\|\s*)@Month @Day,? @YYYY(?=\)\W|\s*[|\n])/gi, "$1@FullMonth @Day, @YYYY")
txt.value=txt.value.replace(/\[\[\d{1,4}#[^\|\]]+\|(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.?|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\]\]/gi, '$1');
.ohc_regex(/([ ]\((?:c\. |))@Month @YYYY ?(?:-|–|&nbsp;) ?@Day @Month @YYYY(?=\)\W)/gi, "$1@FullMonth1 @YYYY1 – @Day @FullMonth2 @YYYY2")
.ohc_regex(/([ ]\((?:c\. |))@Month @YYYY ?(?:-|–|&nbsp;) ?@Month @YYYY(?=\)\W)/gi, "$1@FullMonth1 @YYYY1 – @FullMonth2 @YYYY2")
.ohc_regex(/([ ]\((?:c\. |))@YYYY ?(?:-|–|&nbsp;) ?@Month @YYYY(?=\)\W)/gi, "$1@YYYY1 – @FullMonth @YYYY2")
.ohc_regex(/([ ]\((?:c\. |))@Month ?(?:-|–|&nbsp;) ?@Month @YYYY(?=\)\W)/gi, "$1@FullMonth1 – @FullMonth2 @YYYY")
.ohc_regex(/([ ]\((?:c\. |))@Month @YYYY(?=\)\W)/gi, "$1@FullMonth @YYYY");
}
 
function ohc_abbrev_ref_dates(editor) {
// month and day piped
editor
txt.value=txt.value.replace(/(\d{4,4}-)\[\[(?:Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.?|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))[\s_]\d{1,2}(?:th|st|nd|rd|)\|(\d-)(\d)\]\]/gi, '$10$20$3');
.ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)@Day @Month @YYYY(?=\s*[|}])/gi, "$1@Day @Mon @YYYY")
txt.value=txt.value.replace(/(\d{4,4}-)\[\[(?:Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.?|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))[\s_]\d{1,2}(?:th|st|nd|rd|)\|(\d\d-)(\d)\]\]/gi, '$1$20$3');
txt .value=txt.value.replaceohc_regex(/(\d{4,4}-)\[\<ref[^>]*>(?:Jan([^<]+?:uary|[\s\.(]|)|Feb)([12]?:ruary|\.d|30|31)|Mar (?:chJan|\.Feb|)Mar|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.Aug|)Sep|Aug(?:ustOct|\.Nov|Dec)|Sep(?:tember|\.|t\.r?uary|)ch|Oct(?:oberil|\.[ey]|)ust|Nov(?:ember|\.t?em|o)ber)|Dec( (?:ember|19\.d|))20[\s_01])\d{1,2})(?=(?:th|st|nd|rd|)\|(\d[^-)(\dw\d/%,<][^<]*?|)<\]\]/ref>)/gi, '"$101$2 $3'$4");
.ohc_regex(/([ ]\()@Day @Month @YYYY([^-\w\/])/gi, "$1@Day @Mon @YYYY$2")
txt.value=txt.value.replace(/\[\[(?:Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.?|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))[\s_]\d{1,2}(?:th|st|nd|rd|)\|([^\]]{1,30})\]\]/gi, '$1');
txt.value=txt.value.replace(/\[\[\d{1,2}(?:th|st|nd|rd|)[\s_](?:of[\s_])?(?:Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.?|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\|([^\]]{1,30})\]\]/gi, '$1');
txt.value=txt.value.replace(/\[\[(\d{1,2}(?:st|nd|rd|th))\]\]/gi, '$1');
 
.ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)@Month @Day, @YYYY(?=\s*[|}])/gi, "$1@Mon @Day, @YYYY")
//4 digit years piped
.ohc_regex(/(<ref[^>]*>(?:[^<]+?[\s\(]|))(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)(?:r?uary|ch|il|[ey]|ust|(?:t?em|o)ber) ([12]?\d|30|31),( (?:19\d|20[01])\d)(?=(?:[^-\w\/%,<][^<]*?|)<\/ref>)/gi, "$1$2 $3,$4")
txt.value=txt.value.replace(/\[\[\d{1,4}\|([^\]]{1,30})\]\]/gi, '$1');
.ohc_regex(/([^-\w\/])@Month @Day, @YYYY([^-\w\/])/gi, "$1@Mon @Day, @YYYY$2");
}
 
//not currently used
txt.value=txt.value.replace(/(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))(?:, | of )(\d{3,4}[\w\d])/gi, '$1 $2'); //repeat removal of commas and 'of' between month and year
function ohc_abbrev_all_dates(editor) {
editor
.ohc_regex(/([^-\w/])@Day @Month @YYYY(?=[^-\w/])/gi, "$1@Day @Mon @YYYY")
.ohc_regex(/([^-\w/])@Month @Day, @YYYY(?=[^-\w/])/gi, "$1@Mon @Day, @YYYY");
}
 
//not currently used
//double/triple spaces
function ohc_dmy_publication_dates(editor) {
txt.value=txt.value.replace(/(?: ?)(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))/gi, ' $1');
editor
txt.value=txt.value.replace(/(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))( ?)/gi, '$1 ');
.ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)@Month @Day,? @YYYY/gi, "$1@Day @Month @YYYY") // conversion of dates in references outside of the protection loop (eg for quotations etc.)
.ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)(?:\[\[)?@YYYY(?:\]\][-–]\[\[|[-–])@MM[-–]@DD(?:\]\])?(?=\s*[|}])/gi, "$1@Day @Month @YYYY")
 
// replace ISO dates (within parentheses) only within refs
// spaces and commas - mdy birth and death date ranges
.ohc_regex(/(<ref[^>]*>[^<]+?)([ ]\()@YYYY-@MM-@DD(\))(\W[^<]*?<\/ref>)/gi, "$1$2@Day @Month @YYYY$3$4");
txt.value=txt.value.replace(/([^\d][^\w\d])(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s([0-2]?\d|30|31),? (\d{1,3}|[12]?\d{3})(?:[ ]*[-–][ ]*)(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s([0-2]?\d|30|31),? (\d{1,3}|[12]?\d{3})([^\d][^\w\d])/gi, '$1$2 $3, $4 – $5 $6, $7$8');
}
//dmy birth and death date ranges)
 
txt.value=txt.value.replace(/([^\d][^\w\d])([0-2]?\d|30|31)\s(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|)),? (\d{1,3}|[12]?\d{3})(?:\s?[-–]\s?)([0-2]?\d|30|31)\s(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|)),? (\d{1,3}|[12]?\d{3})([^\d][^\w\d])/gi, '$1$2 $3 $4 – $5 $6 $7$8');
function ohc_mdy_publication_dates(editor) {
editor
.ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)@Day @Month @YYYY/gi, "$1@Month @Day, @YYYY") // conversion of dates in references outside of the protection loop (eg for quotations etc.)
.ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)(?:\[\[)?@YYYY(?:\]\][-–]\[\[|[-–])@MM[-–]@DD(?:\]\])?(?=\s*[|}])/gi, "$1@Month @Day, @YYYY")
 
// replace ISO dates (within parentheses) only within refs
.ohc_regex(/(<ref[^>]*>[^<]+?)([ ]\()@YYYY-@MM-@DD(\))(\W[^<]*?<\/ref>)/gi, "$1$2@Month @Day, @YYYY$3$4");
}
 
function Ohc_delink_ISO_to_dmyohc_refs_to_yyyymmdd(editor) {
editor
var txt = document.editform.wpTextbox1;
// Add a tag to the summary box
.ohc_regex(/(\|\s*(?:archive|access)-?date\s*=\s*)@Day @Month @YYYY/gi, "$1@YYYY-@MM-@DD") // conversion of dmy dates to ymd within citation templates
txt.value = yyyymmdd_to_dmy(txt.value); // adapted from User:Plastikspork/datetools.js
.ohc_regex(/(\|\s*(?:archive|access)-?date\s*=\s*)@Month @Day, @YYYY/gi, "$1@YYYY-@MM-@DD") // conversion of mdy dates to ymd within citation templates
txt.value=txt.value.replace(/([^\d\w\/\-%,])(\d{4}-\d\d-\d\d)(<\s?\/ref.*?>)/g, '$1$2 $3');
.replace(/(\{\{use (?:mdy|dmy) dates)(?:\|cs1-dates=\w{1,2}|)(\s*\|date=[^\}\|]+)(?=\}\})/gi, "$1$2|cs1-dates=ly");
}
 
/** ------------------------------------------------------------------------ **/
//code to convert ref ISO-dates outside citation templates
/// EDIT SUMMARIES & USE DMY TEMPLATE
txt.value=txt.value.replace(/(<\s?ref.*?>[^<]+?)([\s\(])(\d{4})-01-0(\d)([^\d\w\/\-%,])([^<]*?<\s?\/ref.*?>)/g, '$1$2$4 January $3$5$6');
// this function modified 2019-03-27 from [[Special:Permalink/846525463]]
txt.value=txt.value.replace(/(<\s?ref.*?>[^<]+?)([\s\(])(\d{4})-02-0(\d)([^\d\w\/\-%,])([^<]*?<\s?\/ref.*?>)/g, '$1$2$4 February $3$5$6');
// format parameter must be 'dmy' or 'mdy'
txt.value=txt.value.replace(/(<\s?ref.*?>[^<]+?)([\s\(])(\d{4})-03-0(\d)([^\d\w\/\-%,])([^<]*?<\s?\/ref.*?>)/g, '$1$2$4 March $3$5$6');
function ohc_use_dates_template(editor, format) {
txt.value=txt.value.replace(/(<\s?ref.*?>[^<]+?)([\s\(])(\d{4})-04-0(\d)([^\d\w\/\-%,])([^<]*?<\s?\/ref.*?>)/g, '$1$2$4 April $3$5$6');
// current month-year
txt.value=txt.value.replace(/(<\s?ref.*?>[^<]+?)([\s\(])(\d{4})-05-0(\d)([^\d\w\/\-%,])([^<]*?<\s?\/ref.*?>)/g, '$1$2$4 May $3$5$6');
var currentDate = new Date();
txt.value=txt.value.replace(/(<\s?ref.*?>[^<]+?)([\s\(])(\d{4})-06-0(\d)([^\d\w\/\-%,])([^<]*?<\s?\/ref.*?>)/g, '$1$2$4 June $3$5$6');
var currmonth = currentDate.getMonth();
txt.value=txt.value.replace(/(<\s?ref.*?>[^<]+?)([\s\(])(\d{4})-07-0(\d)([^\d\w\/\-%,])([^<]*?<\s?\/ref.*?>)/g, '$1$2$4 July $3$5$6');
var curryear = currentDate.getFullYear();
txt.value=txt.value.replace(/(<\s?ref.*?>[^<]+?)([\s\(])(\d{4})-08-0(\d)([^\d\w\/\-%,])([^<]*?<\s?\/ref.*?>)/g, '$1$2$4 August $3$5$6');
var myMonths = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
txt.value=txt.value.replace(/(<\s?ref.*?>[^<]+?)([\s\(])(\d{4})-09-0(\d)([^\d\w\/\-%,])([^<]*?<\s?\/ref.*?>)/g, '$1$2$4 September $3$5$6');
var curryyyymm = myMonths[currmonth] + " " + curryear;
txt.value=txt.value.replace(/(<\s?ref.*?>[^<]+?)([\s\(])(\d{4})-10-0(\d)([^\d\w\/\-%,])([^<]*?<\s?\/ref.*?>)/g, '$1$2$4 October $3$5$6');
txt.value=txt.value.replace(/(<\s?ref.*?>[^<]+?)([\s\(])(\d{4})-11-0(\d)([^\d\w\/\-%,])([^<]*?<\s?\/ref.*?>)/g, '$1$2$4 November $3$5$6');
txt.value=txt.value.replace(/(<\s?ref.*?>[^<]+?)([\s\(])(\d{4})-12-0(\d)([^\d\w\/\-%,])([^<]*?<\s?\/ref.*?>)/g, '$1$2$4 December $3$5$6');
txt.value=txt.value.replace(/(<\s?ref.*?>[^<]+?)([\s\(])(\d{4})-01-([1-3]\d)([^\d\w\/\-%,])([^<]*?<\s?\/ref.*?>)/g, '$1$2$4 January $3$5$6');
txt.value=txt.value.replace(/(<\s?ref.*?>[^<]+?)([\s\(])(\d{4})-02-([1-3]\d)([^\d\w\/\-%,])([^<]*?<\s?\/ref.*?>)/g, '$1$2$4 February $3$5$6');
txt.value=txt.value.replace(/(<\s?ref.*?>[^<]+?)([\s\(])(\d{4})-03-([1-3]\d)([^\d\w\/\-%,])([^<]*?<\s?\/ref.*?>)/g, '$1$2$4 March $3$5$6');
txt.value=txt.value.replace(/(<\s?ref.*?>[^<]+?)([\s\(])(\d{4})-04-([1-3]\d)([^\d\w\/\-%,])([^<]*?<\s?\/ref.*?>)/g, '$1$2$4 April $3$5$6');
txt.value=txt.value.replace(/(<\s?ref.*?>[^<]+?)([\s\(])(\d{4})-05-([1-3]\d)([^\d\w\/\-%,])([^<]*?<\s?\/ref.*?>)/g, '$1$2$4 May $3$5$6');
txt.value=txt.value.replace(/(<\s?ref.*?>[^<]+?)([\s\(])(\d{4})-06-([1-3]\d)([^\d\w\/\-%,])([^<]*?<\s?\/ref.*?>)/g, '$1$2$4 June $3$5$6');
txt.value=txt.value.replace(/(<\s?ref.*?>[^<]+?)([\s\(])(\d{4})-07-([1-3]\d)([^\d\w\/\-%,])([^<]*?<\s?\/ref.*?>)/g, '$1$2$4 July $3$5$6');
txt.value=txt.value.replace(/(<\s?ref.*?>[^<]+?)([\s\(])(\d{4})-08-([1-3]\d)([^\d\w\/\-%,])([^<]*?<\s?\/ref.*?>)/g, '$1$2$4 August $3$5$6');
txt.value=txt.value.replace(/(<\s?ref.*?>[^<]+?)([\s\(])(\d{4})-09-([1-3]\d)([^\d\w\/\-%,])([^<]*?<\s?\/ref.*?>)/g, '$1$2$4 September $3$5$6');
txt.value=txt.value.replace(/(<\s?ref.*?>[^<]+?)([\s\(])(\d{4})-10-([1-3]\d)([^\d\w\/\-%,])([^<]*?<\s?\/ref.*?>)/g, '$1$2$4 October $3$5$6');
txt.value=txt.value.replace(/(<\s?ref.*?>[^<]+?)([\s\(])(\d{4})-11-([1-3]\d)([^\d\w\/\-%,])([^<]*?<\s?\/ref.*?>)/g, '$1$2$4 November $3$5$6');
txt.value=txt.value.replace(/(<\s?ref.*?>[^<]+?)([\s\(])(\d{4})-12-([1-3]\d)([^\d\w\/\-%,])([^<]*?<\s?\/ref.*?>)/g, '$1$2$4 December $3$5$6');
 
// step 1: normalize redirect template names to canonical template names 'Use dmy dates' or 'Use mdy dates' according to 'format' argument
Ohc_remove_leading_zeros_from_nonlinked_dates ();
editor
// rename redirects 'dmy', 'mdy', 'usedmydates', 'usemdydates' ('usedmydates' and 'usemdydates' are not currently listed as redirects but might be encountered?)
.replace(/\{\{ *(?:use(?:dmy|mdy)dates|dmy|mdy) *([\|\}])/gi, "{{Use " + format + " dates$1")
 
// rename redirects 'usedmy', 'usemdy', 'use dmy', 'use mdy' to canonical form
.replace(/\{\{ *use *(?:dmy|mdy) *([\|\}])/gi, "{{Use " + format + " dates$1")
 
// strip leading / trailing whitespace from 'use xxx dates'
.replace(/\{\{ *use (?:dmy|mdy) dates *([\|\}])/gi, "{{Use " + format + " dates$1");
 
// step 2: look for a canonical template name (the above might not have had anthing to work on) ; if found continue, write new template else
var rxpdd = new RegExp("{{Use " + format + " dates", "gi"); // here we search for canonical form {{use xxx dates}} that has current date
var origtext = editor.get();
var dflagfound = origtext.search(rxpdd);
if (dflagfound === -1) {
var dflagtxt = "{{Use " + format + " dates|date=" + curryyyymm + "}}\r\n"; // not found so insert new template within head matter
// Strategy: line by line
// Strip comments and outside whitespace
// If the line begins with {{ or is blank
// If it has balanced {{ and }} and ends with }}, and has no content outside braces
// If it starts with short description prepend to result
// Else append to result
// Else if it has one more {{ than }} and starts with {{Multiple issues or a redirect
// Append to result
// Keep reading lines and append until a line that has the matching }}
// Otherwise insert the flag text before any trailing blank lines or comment-only lines
var lines = origtext.split(/\r*\n/);
var result= "";
var nesting = 0;
var inmulti = false;
for (let i = 0; i < lines.length; i++) {
var line = lines[i];
var linenosp = line.replaceAll(/<!--.*?-->/g, "").replaceAll(/".*?"/g, '""').replaceAll(/\s+/g, "");
var openbrct = linenosp.includes("{{") ? linenosp.match(/\{\{/g).length : 0;
var closebrct = linenosp.includes("}}") ? linenosp.match(/}}/g).length : 0;
var hascontent = !linenosp.startsWith("{{") || !linenosp.endsWith("}}") || linenosp.search(/}}[^{]+?\{\{/) >= 0;
nesting += openbrct - closebrct;
inmulti |= (nesting > 0 && linenosp.search(/\{\{((multiple)?issues|mi)(\||$)/i) >= 0); // Several redirects in use; extend this list?
// The following are circumstances where we want to transfer the line now. If nesting ever goes negative something is badly wrong.
if (linenosp.length === 0 ||
(nesting === 0 && (!hascontent || inmulti)) || // If nesting goes to 0 when inmulti, this line closes the multi
(nesting > 0 && inmulti)) {
// Hoist Short Description, unless it is preceded on the same line by other text
if (i > 0 && linenosp.search(/^\{\{shortdesc/i) === 0 && !inmulti) {
result = line + "\r\n" + result;
} else {
result += line + "\r\n";
}
if (nesting === 0) {
inmulti = false;
}
} else {
// Detected end of preceding templates
// You might think that we should add a trailing newline if there was one in the original, but the source editor adds one unconditionally
editor.set((result.includes("\r\n") ? result.replace(/\r\n((\r\n)*)$/, "\r\n" + dflagtxt + "$1") : dflagtxt) + lines.slice(i).join("\r\n"));
return;
}
}
// Somehow there is no content, only hatnotes and stuff
editor.set(result + dflagtxt);
return; // and done
}
 
// step 3: rewrite existing canonical templates; add or refresh |date= to current month year; preserve |cs1-dates= as is
editor
.replace(/(\{\{use (?:dmy|mdy) dates)\| *date *=[^\|]*\| *cs1\-dates *= *([^\|\}]*?) *\}\}/gi, "$1|date=" + curryyyymm + "|cs1-dates=$2}}") // with |date= followed by |cs1-dates=
.replace(/(\{\{use (?:dmy|mdy) dates)\| *cs1\-dates *= *([^\|\}]*?) *\| *date *=[^\}]*\}\}/gi, "$1|date=" + curryyyymm + "|cs1-dates=$2}}") // with |cs1-dates= followed by |date=
.replace(/(\{\{use (?:dmy|mdy) dates)\| *date *=[^\|\}]*\}\}/gi, "$1|date=" + curryyyymm + "}}") // with |date=
.replace(/(\{\{use (?:dmy|mdy) dates)\| *cs1\-dates *= *([^\|\}]*?) \}\}/gi, "$1|date=" + curryyyymm + "|cs1-dates=$2}}") // with |cs1-dates
.replace(/(\{\{use (?:dmy|mdy) dates)\}\}/gi, "$1|date=" + curryyyymm + "}}") // no parameters so add |date=curryyyymm
.replace(/(\{\{[\t_ ]*use[\t_ ]+(?:dmy|mdy)[\t_ ]+dates[^{}]*\}\})([\r\n\t ]*)(\{\{[\t ]*short description[^{}]*\}\})/gi, "$3$2$1"); // repositioning "short description" template at the top
}
function Ohc_delink_ISO_to_mdy() {
var txt = document.editform.wpTextbox1;
txt.value = yyyymmdd_to_mdy(txt.value); // adapted from User:Plastikspork/datetools.js
txt.value=txt.value.replace(/([^\d\w\/\-%,])(\d{4}-\d\d-\d\d)(<\s?\/ref.*?>)/g, '$1$2 $3');
 
//code to convert ref ISO-dates outside citation templates
txt.value=txt.value.replace(/(<\s?ref.*?>[^<]+?)([\s\(])(\d{4})-01-0(\d)([^\d\w\/\-%,])([^<]*?<\s?\/ref.*?>)/g, '$1$2January $4, $3$5$6');
txt.value=txt.value.replace(/(<\s?ref.*?>[^<]+?)([\s\(])(\d{4})-02-0(\d)([^\d\w\/\-%,])([^<]*?<\s?\/ref.*?>)/g, '$1$2February $4, $3$5$6');
txt.value=txt.value.replace(/(<\s?ref.*?>[^<]+?)([\s\(])(\d{4})-03-0(\d)([^\d\w\/\-%,])([^<]*?<\s?\/ref.*?>)/g, '$1$2March $4, $3$5$6');
txt.value=txt.value.replace(/(<\s?ref.*?>[^<]+?)([\s\(])(\d{4})-04-0(\d)([^\d\w\/\-%,])([^<]*?<\s?\/ref.*?>)/g, '$1$2April $4, $3$5$6');
txt.value=txt.value.replace(/(<\s?ref.*?>[^<]+?)([\s\(])(\d{4})-05-0(\d)([^\d\w\/\-%,])([^<]*?<\s?\/ref.*?>)/g, '$1$2May $4, $3$5$6');
txt.value=txt.value.replace(/(<\s?ref.*?>[^<]+?)([\s\(])(\d{4})-06-0(\d)([^\d\w\/\-%,])([^<]*?<\s?\/ref.*?>)/g, '$1$2June $4, $3$5$6');
txt.value=txt.value.replace(/(<\s?ref.*?>[^<]+?)([\s\(])(\d{4})-07-0(\d)([^\d\w\/\-%,])([^<]*?<\s?\/ref.*?>)/g, '$1$2July $4, $3$5$6');
txt.value=txt.value.replace(/(<\s?ref.*?>[^<]+?)([\s\(])(\d{4})-08-0(\d)([^\d\w\/\-%,])([^<]*?<\s?\/ref.*?>)/g, '$1$2August $4, $3$5$6');
txt.value=txt.value.replace(/(<\s?ref.*?>[^<]+?)([\s\(])(\d{4})-09-0(\d)([^\d\w\/\-%,])([^<]*?<\s?\/ref.*?>)/g, '$1$2September $4, $3$5$6');
txt.value=txt.value.replace(/(<\s?ref.*?>[^<]+?)([\s\(])(\d{4})-10-0(\d)([^\d\w\/\-%,])([^<]*?<\s?\/ref.*?>)/g, '$1$2October $4, $3$5$6');
txt.value=txt.value.replace(/(<\s?ref.*?>[^<]+?)([\s\(])(\d{4})-11-0(\d)([^\d\w\/\-%,])([^<]*?<\s?\/ref.*?>)/g, '$1$2November $4, $3$5$6');
txt.value=txt.value.replace(/(<\s?ref.*?>[^<]+?)([\s\(])(\d{4})-12-0(\d)([^\d\w\/\-%,])([^<]*?<\s?\/ref.*?>)/g, '$1$2December $4, $3$5$6');
txt.value=txt.value.replace(/(<\s?ref.*?>[^<]+?)([\s\(])(\d{4})-01-([1-3]\d)([^\d\w\/\-%,])([^<]*?<\s?\/ref.*?>)/g, '$1$2January $4, $3$5$6');
txt.value=txt.value.replace(/(<\s?ref.*?>[^<]+?)([\s\(])(\d{4})-02-([1-3]\d)([^\d\w\/\-%,])([^<]*?<\s?\/ref.*?>)/g, '$1$2February $4, $3$5$6');
txt.value=txt.value.replace(/(<\s?ref.*?>[^<]+?)([\s\(])(\d{4})-03-([1-3]\d)([^\d\w\/\-%,])([^<]*?<\s?\/ref.*?>)/g, '$1$2March $4, $3$5$6');
txt.value=txt.value.replace(/(<\s?ref.*?>[^<]+?)([\s\(])(\d{4})-04-([1-3]\d)([^\d\w\/\-%,])([^<]*?<\s?\/ref.*?>)/g, '$1$2April $4, $3$5$6');
txt.value=txt.value.replace(/(<\s?ref.*?>[^<]+?)([\s\(])(\d{4})-05-([1-3]\d)([^\d\w\/\-%,])([^<]*?<\s?\/ref.*?>)/g, '$1$2May $4, $3$5$6');
txt.value=txt.value.replace(/(<\s?ref.*?>[^<]+?)([\s\(])(\d{4})-06-([1-3]\d)([^\d\w\/\-%,])([^<]*?<\s?\/ref.*?>)/g, '$1$2June $4, $3$5$6');
txt.value=txt.value.replace(/(<\s?ref.*?>[^<]+?)([\s\(])(\d{4})-07-([1-3]\d)([^\d\w\/\-%,])([^<]*?<\s?\/ref.*?>)/g, '$1$2July $4, $3$5$6');
txt.value=txt.value.replace(/(<\s?ref.*?>[^<]+?)([\s\(])(\d{4})-08-([1-3]\d)([^\d\w\/\-%,])([^<]*?<\s?\/ref.*?>)/g, '$1$2August $4, $3$5$6');
txt.value=txt.value.replace(/(<\s?ref.*?>[^<]+?)([\s\(])(\d{4})-09-([1-3]\d)([^\d\w\/\-%,])([^<]*?<\s?\/ref.*?>)/g, '$1$2September $4, $3$5$6');
txt.value=txt.value.replace(/(<\s?ref.*?>[^<]+?)([\s\(])(\d{4})-10-([1-3]\d)([^\d\w\/\-%,])([^<]*?<\s?\/ref.*?>)/g, '$1$2October $4, $3$5$6');
txt.value=txt.value.replace(/(<\s?ref.*?>[^<]+?)([\s\(])(\d{4})-11-([1-3]\d)([^\d\w\/\-%,])([^<]*?<\s?\/ref.*?>)/g, '$1$2November $4, $3$5$6');
txt.value=txt.value.replace(/(<\s?ref.*?>[^<]+?)([\s\(])(\d{4})-12-([1-3]\d)([^\d\w\/\-%,])([^<]*?<\s?\/ref.*?>)/g, '$1$2December $4, $3$5$6');
 
 
Ohc_remove_leading_zeros_from_nonlinked_dates ();
/** ------------------------------------------------------------------------ **/
/// DATE PROTECTION
 
var linkmap = [];
 
function ohc_protect_dates(editor) {
// protects dates within links, quotes, etc
// the sensitive part is stored and replaced with a unique identifier,
// which is later replaced with the stored part.
var protect_function = function(s, begin, replace, end) {
linkmap.push(replace);
return begin + "⍌"+(linkmap.length-1)+"⍍" + end;
};
 
editor
// \|x=
.replace(/(<timeline>)([\s\S]*?)(<\/timeline>)/gi, protect_function)
.replace(/(<!--)([^<\{\}]*?)(-->)/gi, protect_function)
.replace(/(<math>)([\s\S]*?)(<\/math>)/gi, protect_function)
.replace(/((?:{(?:Wikimedia |)Commons ?|C ?))(Cat(?:egory|))\|[^{}*](})/gi, protect_function)
.replace(/(<ref)([^>]+)(>)/gi, protect_function)
.replace(/((?:Category|Image|File):)([^|\]]*)([|\]])/gi, protect_function)
.replace(/(\{(?:See ?also|Main))(\|[^}]*)(\})/gi, protect_function)
.replace(/(\{\{(?:double ?|external ?|wide ?)image\s?\|)([^}]+)(\})/gi, protect_function)
.replace(/(\{\{(?:Single chart|harvnb|r|wikisource)\|)([^}]+)(\})/gi, protect_function)
.replace(/(\{\{(?:About-distinguish-text)\s*\|)([^}]+)(\}\})/gi, protect_function)
.replace(/(\{\{(?:Canadian federal by-election))([^}]+)(\}\})/gi, protect_function)
 
.replace(/(\[(?:https?:|ftp:))([^\]]*)(\])/gi, protect_function)
.replace(/(>[ ]*(?:https?:|ftp:))([^< >\]]*)([ ]*<)/gi, protect_function)
.replace(/(\|\s*archive-?url\s*=\s*https?:|ftp:)([^\s\|]*)(\s?\|)/gi, protect_function) //repurposed unused line to protect archive url links (archive.today)
.replace(/(<blockquote>)([\s\S]*?)(<\/blockquote>)/gi, protect_function)
.replace(/(<noinclude>)([\s\S]*?)(<\/noinclude>)/gi, protect_function)
.replace(/(<gallery)([\s\S]*?)(<\/gallery>)/gi, protect_function)
.replace(/(<poem>)([\s\S]*?)(<\/poem>)/gi, protect_function)
.replace(/(\{[^\{]{0,6}(?:quot[^|]{1,7}\s?|sic)\|)([^}]+)(\})/gi, protect_function)
.replace(/((?:image\d?|image_skyline|image[ _]___location\d?|image[ _]name|image[ _]file|img|map\d|pic)\s*=)([^|}]*)([|}])/gi, protect_function)
.replace(/([\|\{]\s*(?:file(?:name\d?|)|image\d?|image ___location\d?|img|pic|Cover|(?:trans-?|)title|quote|chapter|journal|url|archiveurl|work|doi|club|at|volume|reporter)\s*=)([^|\}⍍]*)([|}])/gi, protect_function)
.replace(/([\|\{]\s*(?:file(?:name\d?|)|image\d?|image ___location\d?|img|pic|Cover|(?:trans-?|)title|quote|chapter|journal|url|archiveurl|work|doi|club|at|volume|reporter)\s*=)([^|\}⍍]*)([|}])/gi, protect_function)
.replace(/([\|\{]\s*(?:season)\s*=)(\s*\[\[[^\]]*\]\]\s*)([|}])/gi, protect_function)
.replace(/([\|\{]\s*(?:[xy])\s*=)(\s*[^\|]+\s*)(\|)/gi, protect_function)
.replace(/(\{\{navsource\|)([^}]+)(\})/gi, protect_function)
.replace(/(\{\{merge(?:[^}]+))([^}]+)(\})/gi, protect_function)
.replace(/(\{\{(?:singlechart)\|)([^}]+)(\})/gi, protect_function)
.replace(/(\{\{(?:defaultsort|graph):)([^}]+)(\})/gi, protect_function)
.replace(/(["“])([^"”\n]*)(["”])/gi, protect_function)
.replace(/(.)(\(\{\{by\|[12]\d{3}\}\}[-–]\{\{by\|)([12]\d{3}[ ]*\}\}\))/gi, protect_function)
.replace(/(.)(\(\{\{by\|[12]\d{3}\}\}(?:[-–]present|))(\))/gi, protect_function)
.replace(/(\[\[)(4AD)(\]\]|\|)/gi, protect_function)
 
// retraining redirects containing a date
.replace(/(\[\[)(?:September 3 Society)(\]\]|\|)/gi, "$1Jiusan Society$2")
.replace(/(\[\[)(?:June 4th incident)(\]\]|\|)/gi, "$11989 Tiananmen Square protests and massacre$2")
.replace(/(\[\[)(?:5@th? October (?:\(Serbia\)|overthrow))(\]\]|\|)/gi, "$1Overthrow of Slobodan Milošević$2")
.replace(/(\[\[)(?:October 5@th?(?: \(Serbia\)| overthrow|, 2000))(\]\]|\|)/gi, "$1Overthrow of Slobodan Milošević$2")
 
// protect alternate meanings of 'may' and 'march' (note: not case insensitive)
//.ohc_regex(/([^\w])(@day,?\s{0,3}may)([^\w][^\d])/g, protect_function) //disabled 26 May – not case senstitve: false negatives in converting dates in May
.ohc_regex(/([^\w])(march\s@day)(\s(?:mile|kilomet|met))/g, protect_function)
 
// protect all links containing a date and some text
.ohc_regex(/(\[\[)(\s*\w[^\]\|\n]+?@day[^\]\|\n]+?@fullmonth[^\]\|\n]*)(\]\]|\|)/gi, protect_function)
.ohc_regex(/(\[\[)([^\]\|\n]*?@day[^\]\|\n]+?@fullmonth(?:,? @year|) \D[^\]\|\n]+\w\s*)(\]\]|\|)/gi, protect_function)
.ohc_regex(/(\[\[)(\s*\w[^\]\|\n]+?@fullmonth[^\]\|\n]+?@day[^\]\|\n]*)(\|)/gi, protect_function)
.ohc_regex(/(\[\[)([^\]\|\n]*?@fullmonth[^\]\|\n]+?@day(?:, @year|) \D[^\]\|\n]+\w\s*)(\]\]|\|)/gi, protect_function)
 
// protects certain dates
.replace(/(\[\[)(4AD)([\s\S])/gi, protect_function)
.replace(/([\s\S])(March (?:8|14) Alliance)([\s\S])/gi, protect_function)
.replace(/([\s\S])(23rd March 1931: Shaheed)([\s\S])/gi, protect_function)
.replace(/([\s\S])(Long March [1-7])([\s\S])/gi, protect_function)
.replace(/([\s\S])(National September 11 Memorial & Museum)([\s\S])/gi, protect_function)
.replace(/([\s\S])(Queen Elizabeth II September 11th Garden)([\s\S])/gi, protect_function)
.replace(/([\s\S])(Bombay March 12)([\s\S])/gi, protect_function)
.replace(/([\s\S])(movement 2 June)([\s\S])/gi, protect_function)
.replace(/([\s\S])(6th\sof October City)([\s\S])/gi, protect_function)
.replace(/([\s\S])(Party Workers' Liberation Front 30th of May)([\s\S])/gi, protect_function)
.replace(/([\s\S])(4th\sof August regime)([\s\S])/gi, protect_function)
.replace(/([\s\S])(19th\sof April movement)([\s\S])/gi, protect_function)
.replace(/([\s\S])(June 4th (?:incident|museum))([\s\S])/gi, protect_function)
.replace(/([\s\S])(The Battle Of Marston Moor \(July 2nd,? 1644\))([\s\S])/gi, protect_function)
.replace(/([\s\S])(Night of January 16th)([\s\S])/gi, protect_function)
.replace(/([\s\S])(Observance of 5th November Act)([\s\S])/gi, protect_function)
.replace(/(\[\[)(13 May incident)(\|)/gi, protect_function)
.replace(/(\'\'\')(22nd\sof May)(\'\'\')/gi, protect_function)
.replace(/(\[\[)(22nd\sof May \(film\))([|\]\'])/gi, protect_function)
.replace(/(\[\[)(July 12, 2007, Baghdad airstrike)(\|)/gi, protect_function)
 
.replace(/(\[\[)(November 1828)(\]\])/gi, protect_function)
.replace(/(.)(4th\sof July)(.)/gi, protect_function)
.replace(/(\[\[)((?:2300|2000)\s?AD)(\]\])/gi, protect_function)
.replace(/(\[\[)(29 February)(\]\])/gi, protect_function)
.replace(/(\[\[)(February 29)(\]\])/gi, protect_function)
 
// works names
//.replace(/(.)(protect string)(.)/gi, protect_function)
.replace(/(.)(11\/22\/63)(.)/gi, protect_function)
.replace(/(.)(1\.1\.1994)(.)/gi, protect_function)
.replace(/([\s\S])(2\.13\.61)([\s\S])/gi, protect_function)
//.replace(/(.)(4th of July, Asbury)(.)/gi, protect_function) //protected above globally
.replace(/(.)(26 October 1993)(.)/gi, protect_function)
.replace(/(\[\[|\'\')(June 1, 1974)(.)/gi, protect_function)
.replace(/(\[\[|\'\')(July 15, 1972)(.)/gi, protect_function)
.replace(/(\[\[|\'\')(August 1914)(.)/gi, protect_function)
.ohc_regex(/(\[\[|\'\')(@fullmonth @dd@th? \((?:@yyyy |)film\)(?:\|@fullmonth @dd@th?|))([\s\S])/gi, protect_function)
.ohc_regex(/(\[\[|\'\')(@dd@th? @fullmonth \((?:@yyyy |)film\)(?:\|@dd@th? @fullmonth|))([\s\S])/gi, protect_function)
//.replace(/(Les Bains Douches 18)( December 1979)(.)/gi, protect_function)
.replace(/(August)( 7, 4:15)(.)/gi, protect_function)
.replace(/(In Concert, Zürich, October)( 28, 1979)(.)/gi, protect_function)
.replace(/(CBGB OMFUG Masters: Live June)( 29, 2001)(.)/gi, protect_function)
.ohc_regex(/(Live at [\w ]*,? [1-3]\d)( @fullmonth)(.)/gi, protect_function)
.ohc_regex(/(Live at [\w ]*,? @fullmonth)( @dd)(.)/gi, protect_function)
.ohc_regex(/(Bootmoon Series: [\w ]*[-–] @fullmonth)( @day, @YYYY)(.)/gi, protect_function)
 
// expressions and grammatical strings including modal "may"
//.replace(/(trappist-)(\d{1,3})( may )/g, protect_function) //prospective regex if the line below gives false positives
.replace(/(\W)((?:\d{1,3}) may )(\w\w+)/g, protect_function)
.replace(/(\W)((?:\d{3}|3[2-9]|[4-9]\d)\/\d dec(?:l\.?|))(\W)/gi, protect_function)
.replace(/(\W)((?:\d{2,3})\/\d dec(?:l\.?|))( \(\d\d? overs)/gi, protect_function);
}
function Ohc_delink_year_in_X(){
var txt=document.editform.wpTextbox1;
 
/** ------------------------------------------------------------------------ **/
txt.value=txt.value.replace(/{{(?:avyear|by|baseball\syear|fy|ly|mlby|mlb\syear|scy|sdy)\|(\d{1,4})}}/gi, '$1');
/// DATE PROTECTION FOR ALL REF SECTION
txt.value=txt.value.replace(/{{(?:avyear|by|baseball\syear|fy|ly|mlby|mlb\syear|scy|sdy)\|(?:\d{1,4})\|(\d{1,4})}}/gi, '$1');
txt.value=txt.value.replace(/\[\[\d{1,4}\sin\s[^\|]+\|(\d{1,4})\]\]/gi, '$1');
txt.value=txt.value.replace(/\[\[(?:\d{4}.\d{2} in English football)\|([^\]]{1,30})\]\]/gi, '$1');
 
var linkmap = [];
txt.value=txt.value.replace(/\[\[\d{4,4} Major League Baseball season\|(\d{4,4})(\sseason)?\]\]/gi, '$1$2');
 
function ohc_protect_dates_ref(editor) {
// protects dates within links, quotes, etc
// the sensitive part is stored and replaced with a unique identifier,
// which is later replaced with the stored part.
var protect_function = function (s, begin, replace, end) {
linkmap.push(replace);
return begin + "⍌" + (linkmap.length - 1) + "⍍" + end;
};
 
editor
.replace(/(<ref\s?(?:>|name=[^>]+))([^<]+)(<\/ref>)/gi, protect_function)
.replace(/(<timeline>)([\s\S]*?)(<\/timeline>)/gi, protect_function)
.replace(/(<math>)([\s\S]*?)(<\/math>)/gi, protect_function)
.replace(/((?:{(?:Wikimedia |)Commons ?|C ?))(Cat(?:egory|))\|[^{}*](})/gi, protect_function)
.replace(/((?:Category|Image|File):)([^|\]]*)([|\]])/gi, protect_function)
.replace(/(\{(?:See ?also|Main))(\|[^}]*)(\})/gi, protect_function)
.replace(/(\{\{(?:double ?|external ?|wide ?)image\s?\|)([^}]+)(\})/gi, protect_function)
.replace(/(\{\{(?:harvnb|wikisource)\|)([^}]+)(\})/gi, protect_function)
.replace(/(\[(?:https?:|ftp:))([^\]]*)(\])/gi, protect_function)
.replace(/(>[ ]*(?:https?:|ftp:))([^< >\]]*)([ ]*<)/gi, protect_function)
.replace(/(\|archive-?url=https?:|ftp:)([^\s\|]*)(\|)/gi, protect_function) //repurposed unused line to protect archive url links (archive.today)
.replace(/(<blockquote>)([\s\S]*?)(<\/blockquote>)/gi, protect_function)
.replace(/(\{[^\{]{0,6}(?:quot[^|]{1,7}\s?|sic)\|)([^}]+)(\})/gi, protect_function)
.replace(/((?:image\d?|image_skyline|image[ _]___location\d?|image[ _]name|image[ _]file|img|pic)\s*=)([^|}]*)([|}])/gi, protect_function)
.replace(/([\|\{]\s*(?:file(?:name\d?|)|image\d?|image ___location\d?|img|pic|Cover|title|quote|chapter|journal|url|archiveurl|work|doi|club|at|volume|reporter)\s*=)([^|\}⍍]*)([|}])/gi, protect_function)
.replace(/([\|\{]\s*(?:file(?:name\d?|)|image\d?|image ___location\d?|img|pic|Cover|title|quote|chapter|journal|url|archiveurl|work|doi|club|at|volume|reporter)\s*=)([^|\}⍍]*)([|}])/gi, protect_function)
.replace(/([\|\{]\s*(?:season)\s*=)(\s*\[\[[^\]]*\]\]\s*)([|}])/gi, protect_function)
.replace(/(\{\{navsource\|)([^}]+)(\})/gi, protect_function)
.replace(/(\{\{singlechart\|)([^}]+)(\})/gi, protect_function)
.replace(/(\{\{defaultsort:)([^}]+)(\})/gi, protect_function)
.replace(/([\s\(>]")([^"\n]*)(")/gi, protect_function)
.replace(/([\s\(>]“)([^”\n]*)(”)/gi, protect_function)
.replace(/(.)(\(\{\{by\|[12]\d{3}\}\}[-–]\{\{by\|)([12]\d{3}[ ]*\}\}\))/gi, protect_function)
.replace(/(.)(\(\{\{by\|[12]\d{3}\}\}(?:[-–]present|))(\))/gi, protect_function)
 
// retraining redirects containing a date
.replace(/(\[\[)(?:September 3 Society)(\]\]|\|)/gi, "$1Jiusan Society$2")
.replace(/(\[\[)(?:June 4th incident)(\]\]|\|)/gi, "$1Tiananmen Square protests of 1989$2")
.ohc_regex(/(\[\[)(?:5@th? October (?:\(Serbia\)|overthrow))(\]\]|\|)/gi, "$1Overthrow of Slobodan Milošević$2")
.ohc_regex(/(\[\[)(?:October 5@th?(?: \(Serbia\)| overthrow|, 2000))(\]\]|\|)/gi, "$1Overthrow of Slobodan Milošević$2")
 
// protect alternate meanings of 'may' and 'march' (note: not case insensitive)
.ohc_regex(/([^\w])(@day,?\s{0,3}may)([^\w][^\d])/g, protect_function)
.ohc_regex(/([^\w])(march\s@day)(\s(?:mile|kilomet|met))/g, protect_function)
 
// protect all links containing a date and some text
.ohc_regex(/(\[\[)(\s*\w[^\]\|\n]+?@day[^\]\|\n]+?@fullmonth[^\]\|\n]*)(\]\]|\|)/gi, protect_function)
.ohc_regex(/(\[\[)([^\]\|\n]*?@day[^\]\|\n]+?@fullmonth(?:,? @year|) \D[^\]\|\n]+\w\s*)(\]\]|\|)/gi, protect_function)
.ohc_regex(/(\[\[)(\s*\w[^\]\|\n]+?@fullmonth[^\]\|\n]+?@day[^\]\|\n]*)(\|)/gi, protect_function)
.ohc_regex(/(\[\[)([^\]\|\n]*?@fullmonth[^\]\|\n]+?@day(?:, @year|) \D[^\]\|\n]+\w\s*)(\]\]|\|)/gi, protect_function)
 
// protects certain dates
.replace(/(\[\[)(4AD)([\s\S])/gi, protect_function)
.replace(/([\s\S])(March (?:8|14) Alliance)([\s\S])/gi, protect_function)
.replace(/([\s\S])(23rd March 1931: Shaheed)([\s\S])/gi, protect_function)
.replace(/([\s\S])(Long March [1-7])([\s\S])/gi, protect_function)
.replace(/([\s\S])(Bombay March 12)([\s\S])/gi, protect_function)
.replace(/([\s\S])(movement 2 June)([\s\S])/gi, protect_function)
.replace(/([\s\S])(6th\sof October City)([\s\S])/gi, protect_function)
.replace(/([\s\S])(Party Workers' Liberation Front 30th of May)([\s\S])/gi, protect_function)
.replace(/([\s\S])(4th\sof August regime)([\s\S])/gi, protect_function)
.replace(/([\s\S])(19th\sof April movement)([\s\S])/gi, protect_function)
.replace(/([\s\S])(June 4th incident)([\s\S])/gi, protect_function)
.replace(/([\s\S])(The Battle Of Marston Moor \(July 2nd,? 1644\))([\s\S])/gi, protect_function)
.replace(/([\s\S])(Night of January 16th)([\s\S])/gi, protect_function)
.replace(/([\s\S])(Observance of 5th November Act)([\s\S])/gi, protect_function)
.replace(/(\[\[)(13 May incident)(\|)/gi, protect_function)
.replace(/(\'\'\')(22nd\sof May)(\'\'\')/gi, protect_function)
.replace(/(\[\[)(22nd\sof May \(film\))([|\]\'])/gi, protect_function)
.replace(/(\[\[)(July 12, 2007, Baghdad airstrike)(\|)/gi, protect_function)
 
.replace(/(\[\[)(November 1828)(\]\])/gi, protect_function)
.replace(/(.)(4th\sof July)(.)/gi, protect_function)
.replace(/(\[\[)((?:2300|2000)\s?AD)(\]\])/gi, protect_function)
.replace(/(\[\[)(29 February)(\]\])/gi, protect_function)
.replace(/(\[\[)(February 29)(\]\])/gi, protect_function)
 
// works names
//.replace(/(.)(protect string)(.)/gi, protect_function)
.replace(/(.)(11\/22\/63)(.)/gi, protect_function)
.replace(/(.)(1\.1\.1994)(.)/gi, protect_function)
.replace(/([\s\S])(2\.13\.61)([\s\S])/gi, protect_function)
//.replace(/(.)(4th of July, Asbury)(.)/gi, protect_function) //protected above globally
.replace(/(.)(26 October 1993)(.)/gi, protect_function)
.replace(/(\[\[|\'\')(June 1, 1974)(.)/gi, protect_function)
.replace(/(\[\[|\'\')(July 15, 1972)(.)/gi, protect_function)
.replace(/(\[\[|\'\')(August 1914)(.)/gi, protect_function)
.ohc_regex(/(\[\[|\'\')(@fullmonth @dd@th? \((?:@yyyy |)film\)(?:\|@fullmonth @dd@th?|))([\s\S])/gi, protect_function)
.ohc_regex(/(\[\[|\'\')(@dd@th? @fullmonth \((?:@yyyy |)film\)(?:\|@dd@th? @fullmonth|))([\s\S])/gi, protect_function)
//.replace(/(Les Bains Douches 18)( December 1979)(.)/gi, protect_function)
.replace(/(August)( 7, 4:15)(.)/gi, protect_function)
.replace(/(In Concert, Zürich, October)( 28, 1979)(.)/gi, protect_function)
.replace(/(CBGB OMFUG Masters: Live June)( 29, 2001)(.)/gi, protect_function)
.ohc_regex(/(Live at [\w ]*,? [1-3]\d)( @fullmonth)(.)/gi, protect_function)
.ohc_regex(/(Live at [\w ]*,? @fullmonth)( @dd)(.)/gi, protect_function)
.ohc_regex(/(Bootmoon Series: [\w ]*[-–] @fullmonth)( @day, @YYYY)(.)/gi, protect_function)
 
.replace(/(\W)((?:\d{3}|3[2-9]|[4-9]\d)\/\d dec(?:l\.?|))(\W)/gi, protect_function)
.replace(/(\W)((?:\d{2,3})\/\d dec(?:l\.?|))( \(\d\d? overs)/gi, protect_function);
}
 
 
var linkmap=[];
/** ------------------------------------------------------------------------ **/
function Ohc_protect_dates(){
/// DATE PROTECTION FOR SLASH modules
var txt=document.editform.wpTextbox1;
 
txt.value=txt.value.replace(/Image:[^|]+/gi, function(img){
var linkmap = [];
linkmap.push(img);
 
return "\x02"+(linkmap.length-1)+"\x03";
function ohc_protect_dates_slash(editor) {
});
// protects dates within links, quotes, etc
//protect certain dates
// the sensitive part is stored and replaced with a unique identifier,
txt.value=txt.value.replace(/(\[\[4)(AD)/gi, '$1♫$2');
// which is later replaced with the stored part.
txt.value=txt.value.replace(/(March )((?:8|14) Alliance)/gi, '$1♫$2');
var protect_function = function (s, begin, replace, end) {
txt.value=txt.value.replace(/(6th\sof\s)(October City)/gi, '$1♫$2');
linkmap.push(replace);
txt.value=txt.value.replace(/(\[\[May\s1968)(\]\])/gi, '$1 in France|May 1968$2');
return begin + "⍌" + (linkmap.length - 1) + "⍍" + end;
txt.value=txt.value.replace(/(\[\[June )(1, 1974\]\])/gi, '$1♫$2'); //June 1, 1974 is the name of an album
};
txt.value=txt.value.replace(/(\'\'June )(1, 1974\'\')/gi, '$1♫$2');
 
txt.value=txt.value.replace(/(\[\[(?:2300|2000))\s(AD\]\])/gi, '$1♫$2');
editor
.replace(/(<ref\s?(?:>|name=[^>]+))([^<]+)(<\/ref>)/gi, protect_function)
.replace(/(<timeline>)([\s\S]*?)(<\/timeline>)/gi, protect_function)
.replace(/(<math>)([\s\S]*?)(<\/math>)/gi, protect_function)
.replace(/((?:{(?:Wikimedia |)Commons ?|C ?))(Cat(?:egory|))\|[^{}*](})/gi, protect_function)
.replace(/((?:Category|Image|File):)([^|\]]*)([|\]])/gi, protect_function)
.replace(/(\{(?:See ?also|Main))(\|[^}]*)(\})/gi, protect_function)
.replace(/(\{\{(?:double ?|external ?|wide ?)image\s?\|)([^}]+)(\})/gi, protect_function)
.replace(/(\{\{(?:harvnb|wikisource)\|)([^}]+)(\})/gi, protect_function)
.replace(/(\[(?:https?:|ftp:))([^\]]*)(\])/gi, protect_function)
.replace(/(>[ ]*(?:https?:|ftp:))([^< >\]]*)([ ]*<)/gi, protect_function)
//.replace(/(https?:|ftp:)([^\s\]]*)([\s\]])/gi, protect_function)
.replace(/(<blockquote>)([\s\S]*?)(<\/blockquote>)/gi, protect_function)
.replace(/(\{[^\{]{0,6}(?:quot[^|]{1,7}\s?|sic)\|)([^}]+)(\})/gi, protect_function)
.replace(/((?:image\d?|image_skyline|image[ _]___location\d?|image[ _]name|image[ _]file|img|pic)\s*=)([^|}]*)([|}])/gi, protect_function)
.replace(/([\|\{]\s*(?:file(?:name\d?|)|image\d?|image ___location\d?|img|pic|Cover|title|quote|chapter|journal|url|archiveurl|work|doi|club|at|volume|reporter)\s*=)([^|\}⍍]*)([|}])/gi, protect_function)
.replace(/([\|\{]\s*(?:file(?:name\d?|)|image\d?|image ___location\d?|img|pic|Cover|title|quote|chapter|journal|url|archiveurl|work|doi|club|at|volume|reporter)\s*=)([^|\}⍍]*)([|}])/gi, protect_function)
.replace(/([\|\{]\s*(?:season)\s*=)(\s*\[\[[^\]]*\]\]\s*)([|}])/gi, protect_function)
.replace(/(\{\{navsource\|)([^}]+)(\})/gi, protect_function)
.replace(/(\{\{singlechart\|)([^}]+)(\})/gi, protect_function)
.replace(/(\{\{defaultsort:)([^}]+)(\})/gi, protect_function)
.replace(/([\s\(>]")([^"\n]*)(")/gi, protect_function)
.replace(/([\s\(>]“)([^”\n]*)(”)/gi, protect_function)
.replace(/(.)(\(\{\{by\|[12]\d{3}\}\}[-–]\{\{by\|)([12]\d{3}[ ]*\}\}\))/gi, protect_function)
.replace(/(.)(\(\{\{by\|[12]\d{3}\}\}(?:[-–]present|))(\))/gi, protect_function);
}
function Ohc_unprotect_dates(){
var txt=document.editform.wpTextbox1;
 
function ohc_unprotect_dates(editor) {
//unprotect certain dates
editor
txt.value=txt.value.replace(/(\[\[4)♫(AD)/gi, '$1♫$2');
//unprotect all dates
txt.value=txt.value.replace(/(\[\[(?:8|14))♫(March Alliance)/gi, '$1$2');
txt.value=txt.value .replace(/(6th\sof\s)[(October City)]/gig, '$1$2');
txt.value=txt.value .replace(/(June[0-9]+)⍍/g, function )♫(1x, 1974n)/gi, '$1$2');{
var res = linkmap[n];
txt.value=txt.value.replace(/(\[\[(?:2300|2000))♫(AD]\])/gi, '$1 $2');
res = res.replace(/⍌([0-9]+)⍍/g, function (x, n) {
txt.value=txt.value.replace(/(\w)♫(\w)/g, '$1$2'); //2010-10-06 quick patch to remove any spurious protection markers
var res = linkmap[n];
txt.value=txt.value.replace(/\x02([0-9]+)\x03/g, function(x, n){
res = res.replace(/⍌([0-9]+)⍍/g, function (x, n) {
return linkmap[n];
var res = linkmap[n];
});
res = res.replace(/⍌([0-9]+)⍍/g, function (x, n) {
return linkmap[n];
});
return res;
});
return res;
});
return res;
});
}
 
function ohc_MOSNUM_edit_summary(editor) {
function Ohc_remove_leading_zeros_from_nonlinked_dates () {
editor
var txt=document.editform.wpTextbox1;
.options({ minor: true })
//remove leading zero from nonlinked date
.appendEditSummary("[[Wikipedia:MOSNUMscript|script]]-assisted date audit and style fixes per [[MOS:NUM]]")
txt.value=txt.value.replace(/([^\d][^\w\d])(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s0(\d)(?:th|st|nd|rd|),?\s(\d{4})([^\w\d][^\d]|[ ]*\r)/gi, '$1$2 $3, $4$5');
.clickDiff();
txt.value=txt.value.replace(/([^\d][^\w\d])0(\d)(?:th|st|nd|rd|)\s(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s(\d{4})([^\w\d][^\d]|[ ]*\r)/gi, '$1$2 $3 $4$5');
}
 
function ohc_bigendien_edit_summary(editor) {
txt.value=txt.value.replace(/([^\d][^\w\d])(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s0(\d)(?:th|st|nd|rd|)([^\w\d][^\d]|[ ]*\r)/gi, '$1$2 $3$4');
// add a tag to the summary box
txt.value=txt.value.replace(/([^\d][^\w\d])0(\d)(?:th|st|nd|rd|)\s(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))([^\w\d][^\d]|[ ]*\r)/gi, '$1$2 $3$4');
editor
.options({ minor: true })
.appendEditSummary("ymd ref dates")
.clickDiff();
}
 
function ohc_expand_edit_summary(editor) {
// add a tag to the summary box
editor
.options({ minor: true })
.appendEditSummary("expand month names")
.clickDiff();
}
 
function ohc_slash_edit_summary(editor) {
// add a tag to the summary box
editor
.options({ minor: true })
.appendEditSummary("resolved slash dates")
.clickDiff();
}
 
function Ohc_dates_to_dmyohc_abbrev_edit_summary(editor) {
// add a tag to the summary box
var txt=document.editform.wpTextbox1;
editor
// insert 'dmy' template
.options({ minor: true })
txt.value=txt.value.replace(/{{(use (dmy|mdy) dates|mdy)(\|[^}]*)?}}/gi, '{{Use dmy dates|date=November 2010}}');
.appendEditSummary("abbrev month names")
if (txt.value.search(/{{Use dmy dates|date=November 2010}}/gi) == -1)
.clickDiff();
{
}
txt.value='{{Use dmy dates|date=November 2010}}\r\n'+txt.value;
}
 
/** ------------------------------------------------------------------------ **/
Ohc_code_delink_dates();
/// CUSTOMIZATION POINTS
//repeat protect dates because 'unprotect dates' function is within 'delink dates' function
function ohc_customize_all_to_dmy(editor) { }
Ohc_protect_dates();
function ohc_customize_all_to_mdy(editor) { }
function ohc_customize_body_to_dmy(editor) { }
function ohc_customize_body_to_mdy(editor) { }
function ohc_customize_ISO_to_dmy(editor) { }
function ohc_customize_ISO_to_mdy(editor) { }
 
/** ------------------------------------------------------------------------ **/
//change start and end templates
function ohc_body_dates_to_dmy(editor) {
txt.value=txt.value.replace(/({{(start\sdate|end\sdate)[^|]*\|)df=ye?s?\|([^}]*df=ye?s?)/gi, '$1$2');
ohc_use_dates_template(editor, "dmy");
 
ohc_fix_common_errors(editor);
//change deprecated birth and death templates
ohc_fix_dts_template(editor, "dmy");
txt.value=txt.value.replace(/({{(?:Birth|Death|release|start date|end date)[^}]*)\|mf=ye?s?/gi, '$1');
ohc_fix_gr_template(editor, "dmy");
txt.value=txt.value.replace(/({{(?:Birth|Death|release|start date|end date)[^|]*\|)/gi, '$1df=yes|');
ohc_dates_to_dmy(editor);
txt.value=txt.value.replace(/({{(?:Birth|Death|release|start date|end date)[^|]*\|)df=ye?s?\|([^}]*df=ye?s?)/gi, '$1$2');
ohc_remove_leading_zeroes(editor);
ohc_fix_dmy_redundancies(editor);
}
 
function ohc_body_dates_to_mdy(editor) {
//convert mdy-mdy to dmy-dmy (birth and death date ranges)
ohc_use_dates_template(editor, "mdy");
txt.value=txt.value.replace(/([^\d][^\w\d])(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s([0-2]?\d|30|31), ([12]?\d{0,3})(?:\s?[-–]\s?)(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s([0-2]?\d|30|31), ([12]?\d{0,3})([^\d][^\w\d])/gi, '$1$3 $2 $4 – $6 $5 $7$8');
ohc_fix_common_errors(editor);
ohc_fix_dts_template(editor, "mdy");
ohc_fix_gr_template(editor, "mdy");
ohc_dates_to_mdy(editor);
ohc_remove_leading_zeroes(editor);
ohc_fix_mdy_redundancies(editor);
}
 
/** ------------------------------------------------------------------------ **/
//convert md-mdy date ranges to dm-dmy
function ohc_all_to_dmy_driver(editor) {
txt.value=txt.value.replace(/([^\d][^\w\d])(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s([0-2]?\d|30|31)(?:th|st|nd|rd|)((?:,?\s[0-3]?\d(?:th|st|nd|rd|)){0,6}),?(\/|\s?[-–]\s?|\s(?:and|to|&)\s)([0-2]?\d|30|31)(?:th|st|nd|rd|),?\s(?:of\s)?(\d{3,4}[^\w\d][^\d])/gi, '$1$3$4$5$6 $2 $7');
ohc_extend_editor(editor);
//test code txt.value=txt.value.replace(/([^\d][^\w\d])(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s([0-2]?\d|30|31)(?:th|st|nd|rd|)((?:,?\s[0-3]?\d(?:th|st|nd|rd|)){0,6}),? ([0-2]?\d|30|31)(?:th|st|nd|rd|),?\s(?:of\s)?(\d{3,4}[^\w\d][^\d])/gi, '$1$3$4, $5 $2$6');
txt.value=txt.value.replace(/([^\d][^\w\d])(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s([0-2]?\d|30|31)(?:th|st|nd|rd|)((?:,?\s[0-3]?\d(?:th|st|nd|rd|)){0,6}), ([0-2]?\d|30|31)(?:th|st|nd|rd|)([^\w\d][^\d]|[ ]*\r)/gi, '$1$3$4, $5 $2$6');
 
ohc_delink_dates(editor);
//convert md,d,d, date ranges to d,d,dm (multiple, separated by commas)
ohc_protect_dates(editor);
txt.value=txt.value.replace(/([^\d][^\w\d])(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s([1-3]?\d)(?:th|st|nd|rd|)((?:,?\s[0-3]?\d(?:th|st|nd|rd|)){0,6}),?(\/|\s?[-–]\s?|\s(?:and|to|&)\s)([0-2]?\d|30|31)(?:th|st|nd|rd|)([^\w\d][^\d]|[ ]*\r)/gi, '$1$3$4$5$6 $2$7');
ohc_fix_unambiguous_dates(editor);
txt.value=txt.value.replace(/([^\d][^\w\d])(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))((?:\s[1-3]?\d(?:th|st|nd|rd|),?){1,6})(\s(?:and|to|&)\s)([0-2]?\d|30|31)(?:th|st|nd|rd|)([^\w\d][^\d]|[ ]*\r)/gi, '$1$3$4$5 $2$6');
ohc_body_dates_to_dmy(editor);
txt.value=txt.value.replace(/([^\d][^\w\d])(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s([1-3]?\d)(?:th|st|nd|rd|)((?:,?\s[1-3]?\d(?:th|st|nd|rd|)){1,6})([^\w\d][^\d]|[ ]*\r)/gi, '$1$3$4 $2$5');
ohc_delink_ISO_to_dmy(editor);
//convert md date ranges to dm (simple, separated by hyphens and dashes or 'to')
//ohc_delink_year_in_X(editor);
txt.value=txt.value.replace(/([^\d][^\w\d])(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s([1-3]?\d)(?:th|st|nd|rd|)(\s?[-–]\s?|\sto\s)([0-2]?\d|30|31)(?:th|st|nd|rd|)([^\w\d][^\d]|[ ]*\r)/gi, '$1$3 $4$5 $2$6');
ohc_customize_all_to_dmy(editor);
ohc_ISO_to_dmy_in_citations(editor);
ohc_unprotect_dates(editor);
 
ohc_MOSNUM_edit_summary(editor);
//'md, md,' to 'dm, dm,'
}
txt.value=txt.value.replace(/([^\d])( (Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|)))( [0-2]?\d|30|31),( (Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|)))( [0-2]?\d|30|31)([,\.][^\w\d][^\d])/gi, '$1$3$2,$5$4,$6');
 
function ohc_all_to_mdy_driver(editor) {
//convert simple mdy dates to dmy
ohc_extend_editor(editor);
txt.value=txt.value.replace(/([^\d][^\w\d])(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s([0-2]?\d|30|31)(?:th|st|nd|rd|),?\s(\d{1,4}\s?(?:AD|BC|CE|BCE)[^\w\d][^\d])/gi, '$1$3 $2 $4');
txt.value=txt.value.replace(/([^\d][^\w\d])(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s([0-2]?\d|30|31)(?:th|st|nd|rd|),?\s([12]\d{3})([^\w\d][^\d]|[ ]*\r)/gi, '$1$3 $2 $4$5');
txt.value=txt.value.replace(/([^\d][^\w\d])(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s([0-2]?\d|30|31)(?:th|st|nd|rd|)([^\w\d][^\d]|[ ]*\r)/gi, '$1$3 $2$4');
//Repeat line to capture some instances that get missed first time
//(needed because the date component 'September 19, 1881' within the string 'March 4-September 19, 1881' is blocked from conversion by the '4')
txt.value=txt.value.replace(/([^\d][^\w\d])(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s([0-2]?\d|30|31)(?:th|st|nd|rd|),?\s(\d{1,4})([^\w\d][^\d]|[ ]*\r)/gi, '$1$3 $2 $4$5');
 
ohc_delink_dates(editor);
//Month+day_number " 7th March" -> "7 March"
ohc_protect_dates(editor);
txt.value=txt.value.replace(/([^\d][^\w\d])([0-2]?\d|30|31)(?:th|st|nd|rd|)\s(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s(\d{1,4})([^\w\d][^\d]|[ ]*\r)/gi, '$1$2 $3 $4$5');
ohc_fix_unambiguous_dates(editor);
txt.value=txt.value.replace(/([^\d][^\w\d])([0-2]?\d|30|31)(?:th|st|nd|rd|)\s(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))([^\w\d][^\d]|[ ]*\r)/gi, '$1$2 $3$4');
ohc_body_dates_to_mdy(editor);
ohc_delink_ISO_to_mdy(editor);
//ohc_delink_year_in_X(editor);
ohc_customize_all_to_mdy();
ohc_ISO_to_mdy_in_citations(editor);
ohc_unprotect_dates(editor);
 
ohc_MOSNUM_edit_summary(editor);
Ohc_remove_leading_zeros_from_nonlinked_dates ();
}
//remove comma in International date format
txt.value=txt.value.replace(/([1-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)?),?\s?(\d{3,4})([^\w\d])/gi, '$1 $2 $3$4');
 
function ohc_dmy_cs1_ly_driver(editor) {
Ohc_unprotect_dates();
ohc_extend_editor(editor);
 
ohc_delink_dates(editor);
ohc_protect_dates(editor);
ohc_fix_unambiguous_dates(editor);
ohc_body_dates_to_dmy(editor);
ohc_delink_ISO_to_dmy(editor);
//ohc_delink_year_in_X(editor);
ohc_customize_all_to_dmy(editor);
ohc_ISO_to_dmy_in_citations(editor);
ohc_unprotect_dates(editor);
ohc_refs_to_yyyymmdd(editor);
ohc_MOSNUM_edit_summary(editor);
}
 
function Ohc_dates_to_mdyohc_mdy_cs1_ly_driver(editor) {
ohc_extend_editor(editor);
var txt=document.editform.wpTextbox1;
// insert 'mdy' template
txt.value=txt.value.replace(/{{(use (dmy|mdy) dates|dmy)(\|[^}]*)?}}/gi, '{{Use mdy dates|date=November 2010}}');
if (txt.value.search(/{{Use mdy dates|date=November 2010}}/gi) == -1)
{
txt.value='{{Use mdy dates|date=November 2010}}\r\n'+txt.value;
}
 
ohc_delink_dates(editor);
Ohc_code_delink_dates();
ohc_protect_dates(editor);
//repeat protect dates because 'unprotect dates' function is within 'delink dates' function
ohc_fix_unambiguous_dates(editor);
Ohc_protect_dates();
ohc_body_dates_to_mdy(editor);
ohc_delink_ISO_to_mdy(editor);
//ohc_delink_year_in_X(editor);
ohc_customize_all_to_mdy();
ohc_ISO_to_mdy_in_citations(editor);
ohc_unprotect_dates(editor);
ohc_refs_to_yyyymmdd(editor);
ohc_MOSNUM_edit_summary(editor);
}
 
function ohc_bigendian_driver(editor) {
//change deprecated birth and death templates
ohc_refs_to_yyyymmdd(editor);
txt.value=txt.value.replace(/({{(?:Birth|Death|release|start date|end date)[^}]*)\|df=ye?s?/gi, '$1');
// txt.value=txt.value.replace(/({{(?:Birth|Death|release|start date|end date)[^|]*\|)/gi, '$1mf=yes|');
txt.value=txt.value.replace(/({{(?:Birth|Death|release|start date|end date)[^|]*\|)mf=ye?s?\|([^}]*mf=ye?s?)/gi, '$1$2');
 
ohc_bigendien_edit_summary(editor);
//convert dmy-dmy to mdy-mdy (birth and death date ranges)
}
txt.value=txt.value.replace(/([^\d][^\w\d])([0-2]?\d|30|31)\s(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|)),? ([12]?\d{0,3})(?:\s?[-–]\s?)([0-2]?\d|30|31)\s(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|)),? ([12]?\d{0,3})([^\d][^\w\d])/gi, '$1$3 $2, $4 – $6 $5, $7$8');
 
function ohc_dmy_publication_dates_driver(editor) {
//convert dm-dmy date ranges to md-mdy
ohc_dmy_publication_dates(editor);
txt.value=txt.value.replace(/([^\d][^\w\d])((?:[0-3]?\d)(?:th|st|nd|rd|),\s){0,6}([0-2]?\d|30|31)(?:th|st|nd|rd|)(\/|[\s]{0,3}(?:and|to|&|-|–)[\s]{0,3})([0-2]?\d|30|31)(?:th|st|nd|rd|)\s(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s(\d{3,4}[^\w\d][^\d])/gi, '$1$6 $2$3$4$5, $7');
 
ohc_MOSNUM_edit_summary(editor);
//convert d,d,dm date ranges to md,d,d (multiple, separated by commas)
}
txt.value=txt.value.replace(/([^\d][^\w\d])((?:[0-3]?\d(?:th|st|nd|rd|),?\s){0,6})([0-2]?\d|30|31)(?:th|st|nd|rd|)(\/|[\s]{0,3}(?:and|to|&|-|–)[\s]{0,3})([0-2]?\d|30|31)(?:th|st|nd|rd|)\s(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))([^\w\d][^\d]|[ ]*\r)/gi, '$1$6 $2$3$4$5$7');
txt.value=txt.value.replace(/([^\d][^\w\d])((?:[0-3]?\d(?:th|st|nd|rd|),?[\s]{1,3}){1,6})([0-2]?\d|30|31)(?:th|st|nd|rd|)\s(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))([^\w\d][^\d]|[ ]*\r)/gi, '$1$4 $2$3$5');
//convert dm date ranges to md (simple, separated by hyphen, dash or 'to')
txt.value=txt.value.replace(/([^\d][^\w\d])([0-2]?\d|30|31)(?:th|st|nd|rd|)([\s]{0,3}[-–][\s]{0,3}|\sto[\s]{0,3})([0-2]?\d|30|31)(?:th|st|nd|rd|)[\s]{1,3}(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))([^\w\d][^\d]|[ ]*\r)/gi, '$1$5 $2$3$4$6');
 
function ohc_mdy_publication_dates_driver(editor) {
//'dm, dm,' to 'md, md,'
ohc_extend_editor(editor);
txt.value=txt.value.replace(/([^\d])( [0-2]?\d|30|31)( (Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))),( [0-2]?\d|30|31)( (Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|)))([,\.]?[^\w\d][^\d])/gi, '$1$3$2,$5$4,$6');
 
//ohc_delink_dates(editor);
txt.value=txt.value.replace(/([^\d][^\w\d])([0-2]?\d|30|31)(?:th|st|nd|rd|)[\s]{1,3}(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|)),?\s(\d{1,4}\s?(?:AD|BC|CE|BCE)[^\w\d][^\d])/gi, '$1$3 $2, $4');
ohc_protect_dates(editor);
txt.value=txt.value.replace(/([^\d][^\w\d])([0-2]?\d|30|31)(?:th|st|nd|rd|)[\s]{1,3}(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|)),?\s([12]\d{3})([^\w\d][^\d]|[ ]*\r)/gi, '$1$3 $2, $4$5');
ohc_body_dates_to_mdy(editor);
txt.value=txt.value.replace(/([^\d][^\w\d])([0-2]?\d|30|31)(?:th|st|nd|rd|)[\s]{1,3}(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))([^\w\d][^\d]|[ ]*\r)/gi, '$1$3 $2$4');
ohc_customize_body_to_mdy(editor);
ohc_mdy_publication_dates(editor);
ohc_unprotect_dates(editor);
 
ohc_MOSNUM_edit_summary(editor);
//repeat previous two bits of code to capture some date ranges that were missed first time round
// txt.value=txt.value.replace(/([^\d][^\w\d])([0-2]?\d|30|31)(?:th|st|nd|rd|)\s(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s(\d{1,4})([^\w\d][^\d]|[ ]*\r)/gi, '$1$3 $2, $4$5');
// txt.value=txt.value.replace(/([^\d][^\w\d])([0-2]?\d|30|31)(?:th|st|nd|rd|)\s(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))([^\w\d][^\d]|[ ]*\r)/gi, '$1$3 $2$4');
 
}
//Month+day_number "March 7th" -> "March 7"
txt.value=txt.value.replace(/([^\d][^\w\d])(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s([0-2]?\d|30|31)(?:th|st|nd|rd)([^\w\d][^\d]|[ ]*\r)/gi, '$1$2 $3$4');
 
function ohc_body_to_dmy_driver(editor) {
//add comma when missing
ohc_extend_editor(editor);
txt.value=txt.value.replace(/([^\d][^\w\d])(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))\s([0-2]?\d|30|31)(?:th|st|nd|rd|)(\s\d{1,4}[^\w\d][^\d])/gi, '$1$2 $3,$4');
 
//ohc_delink_dates(editor);
Ohc_remove_leading_zeros_from_nonlinked_dates ();
ohc_protect_dates_ref(editor);
Ohc_unprotect_dates();
ohc_body_dates_to_dmy(editor);
ohc_customize_body_to_dmy(editor);
ohc_unprotect_dates(editor);
 
ohc_MOSNUM_edit_summary(editor);
}
 
function Ohc_MOSNUM_edit_summaryohc_body_to_mdy_driver(editor) {
ohc_extend_editor(editor);
// Add a tag to the summary box
 
var txt=document.editform.wpSummary;
//ohc_delink_dates(editor);
var summary = "[[WP:MOSNUM|unified date formats]] by [[WP:MOSNUMscript|script]]";
ohc_protect_dates_ref(editor);
if (txt.value.indexOf(summary) == -1) {
ohc_body_dates_to_mdy(editor);
if (txt.value.match(/[^\*\/\s][^\/\s]?\s*$/)) {
ohc_customize_body_to_mdy(editor);
txt.value += ", ";
ohc_unprotect_dates(editor);
}
 
txt.value += summary;
ohc_MOSNUM_edit_summary(editor);
}
// document.forms.editform.wpMinoredit.checked = true;
document.editform.wpDiff.click();
}
 
function yyyymmdd_to_dmyohc_ISO_to_dmy_driver(streditor) {
ohc_extend_editor(editor);
// This code adapted from User:Plastikspork/datetools.js
str=str.replace(/(\|[ ]*(?:date|archivedate)[ ]*=[ ]*)(?:\[\[)?([1-2][0-9]{3})(?:\]\]-\[\[|-)0?1-(0[1-9]|[1-2][0-9]|30|31)(?:\]\])?/gi, '$1$3 January $2');
str=str.replace(/(\|[ ]*(?:date|archivedate)[ ]*=[ ]*)(?:\[\[)?([1-2][0-9]{3})(?:\]\]-\[\[|-)0?2-(0[1-9]|[1-2][0-9]|30|31)(?:\]\])?/gi, '$1$3 February $2');
str=str.replace(/(\|[ ]*(?:date|archivedate)[ ]*=[ ]*)(?:\[\[)?([1-2][0-9]{3})(?:\]\]-\[\[|-)0?3-(0[1-9]|[1-2][0-9]|30|31)(?:\]\])?/gi, '$1$3 March $2');
str=str.replace(/(\|[ ]*(?:date|archivedate)[ ]*=[ ]*)(?:\[\[)?([1-2][0-9]{3})(?:\]\]-\[\[|-)0?4-(0[1-9]|[1-2][0-9]|30|31)(?:\]\])?/gi, '$1$3 April $2');
str=str.replace(/(\|[ ]*(?:date|archivedate)[ ]*=[ ]*)(?:\[\[)?([1-2][0-9]{3})(?:\]\]-\[\[|-)0?5-(0[1-9]|[1-2][0-9]|30|31)(?:\]\])?/gi, '$1$3 May $2');
str=str.replace(/(\|[ ]*(?:date|archivedate)[ ]*=[ ]*)(?:\[\[)?([1-2][0-9]{3})(?:\]\]-\[\[|-)0?6-(0[1-9]|[1-2][0-9]|30|31)(?:\]\])?/gi, '$1$3 June $2');
str=str.replace(/(\|[ ]*(?:date|archivedate)[ ]*=[ ]*)(?:\[\[)?([1-2][0-9]{3})(?:\]\]-\[\[|-)0?7-(0[1-9]|[1-2][0-9]|30|31)(?:\]\])?/gi, '$1$3 July $2');
str=str.replace(/(\|[ ]*(?:date|archivedate)[ ]*=[ ]*)(?:\[\[)?([1-2][0-9]{3})(?:\]\]-\[\[|-)0?8-(0[1-9]|[1-2][0-9]|30|31)(?:\]\])?/gi, '$1$3 August $2');
str=str.replace(/(\|[ ]*(?:date|archivedate)[ ]*=[ ]*)(?:\[\[)?([1-2][0-9]{3})(?:\]\]-\[\[|-)0?9-(0[1-9]|[1-2][0-9]|30|31)(?:\]\])?/gi, '$1$3 September $2');
str=str.replace(/(\|[ ]*(?:date|archivedate)[ ]*=[ ]*)(?:\[\[)?([1-2][0-9]{3})(?:\]\]-\[\[|-)10-(0[1-9]|[1-2][0-9]|30|31)(?:\]\])?/gi, '$1$3 October $2');
str=str.replace(/(\|[ ]*(?:date|archivedate)[ ]*=[ ]*)(?:\[\[)?([1-2][0-9]{3})(?:\]\]-\[\[|-)11-(0[1-9]|[1-2][0-9]|30|31)(?:\]\])?/gi, '$1$3 November $2');
str=str.replace(/(\|[ ]*(?:date|archivedate)[ ]*=[ ]*)(?:\[\[)?([1-2][0-9]{3})(?:\]\]-\[\[|-)12-(0[1-9]|[1-2][0-9]|30|31)(?:\]\])?/gi, '$1$3 December $2');
 
ohc_protect_dates(editor);
str=str.replace(/(\|[ ]*accessdate[ ]*=[ ]*)(?:\[\[)?([1-2][0-9]{3})(?:\]\]-\[\[|-)0?1-(0[1-9]|[1-2][0-9]|30|31)(?:\]\])?/gi, '$1$3 January $2');
ohc_delink_ISO_to_dmy(editor);
str=str.replace(/(\|[ ]*accessdate[ ]*=[ ]*)(?:\[\[)?([1-2][0-9]{3})(?:\]\]-\[\[|-)0?2-(0[1-9]|[1-2][0-9]|30|31)(?:\]\])?/gi, '$1$3 February $2');
ohc_customize_ISO_to_dmy(editor);
str=str.replace(/(\|[ ]*accessdate[ ]*=[ ]*)(?:\[\[)?([1-2][0-9]{3})(?:\]\]-\[\[|-)0?3-(0[1-9]|[1-2][0-9]|30|31)(?:\]\])?/gi, '$1$3 March $2');
ohc_unprotect_dates(editor);
str=str.replace(/(\|[ ]*accessdate[ ]*=[ ]*)(?:\[\[)?([1-2][0-9]{3})(?:\]\]-\[\[|-)0?4-(0[1-9]|[1-2][0-9]|30|31)(?:\]\])?/gi, '$1$3 April $2');
 
str=str.replace(/(\|[ ]*accessdate[ ]*=[ ]*)(?:\[\[)?([1-2][0-9]{3})(?:\]\]-\[\[|-)0?5-(0[1-9]|[1-2][0-9]|30|31)(?:\]\])?/gi, '$1$3 May $2');
//ohc_MOSNUM_edit_summary(editor);
str=str.replace(/(\|[ ]*accessdate[ ]*=[ ]*)(?:\[\[)?([1-2][0-9]{3})(?:\]\]-\[\[|-)0?6-(0[1-9]|[1-2][0-9]|30|31)(?:\]\])?/gi, '$1$3 June $2');
str=str.replace(/(\|[ ]*accessdate[ ]*=[ ]*)(?:\[\[)?([1-2][0-9]{3})(?:\]\]-\[\[|-)0?7-(0[1-9]|[1-2][0-9]|30|31)(?:\]\])?/gi, '$1$3 July $2');
str=str.replace(/(\|[ ]*accessdate[ ]*=[ ]*)(?:\[\[)?([1-2][0-9]{3})(?:\]\]-\[\[|-)0?8-(0[1-9]|[1-2][0-9]|30|31)(?:\]\])?/gi, '$1$3 August $2');
str=str.replace(/(\|[ ]*accessdate[ ]*=[ ]*)(?:\[\[)?([1-2][0-9]{3})(?:\]\]-\[\[|-)0?9-(0[1-9]|[1-2][0-9]|30|31)(?:\]\])?/gi, '$1$3 September $2');
str=str.replace(/(\|[ ]*accessdate[ ]*=[ ]*)(?:\[\[)?([1-2][0-9]{3})(?:\]\]-\[\[|-)10-(0[1-9]|[1-2][0-9]|30|31)(?:\]\])?/gi, '$1$3 October $2');
str=str.replace(/(\|[ ]*accessdate[ ]*=[ ]*)(?:\[\[)?([1-2][0-9]{3})(?:\]\]-\[\[|-)11-(0[1-9]|[1-2][0-9]|30|31)(?:\]\])?/gi, '$1$3 November $2');
str=str.replace(/(\|[ ]*accessdate[ ]*=[ ]*)(?:\[\[)?([1-2][0-9]{3})(?:\]\]-\[\[|-)12-(0[1-9]|[1-2][0-9]|30|31)(?:\]\])?/gi, '$1$3 December $2');
return str;
}
 
function yyyymmdd_to_mdyohc_ISO_to_mdy_driver(streditor) {
ohc_extend_editor(editor);
// This code adapted from User:Plastikspork/datetools.js
str=str.replace(/(\|[ ]*(?:date|archivedate)[ ]*=[ ]*)(?:\[\[)?([1-2][0-9]{3})(?:\]\]-\[\[|-)0?1-(0[1-9]|[1-2][0-9]|30|31)(?:\]\])?/gi, '$1January $3, $2');
str=str.replace(/(\|[ ]*(?:date|archivedate)[ ]*=[ ]*)(?:\[\[)?([1-2][0-9]{3})(?:\]\]-\[\[|-)0?2-(0[1-9]|[1-2][0-9]|30|31)(?:\]\])?/gi, '$1February $3, $2');
str=str.replace(/(\|[ ]*(?:date|archivedate)[ ]*=[ ]*)(?:\[\[)?([1-2][0-9]{3})(?:\]\]-\[\[|-)0?3-(0[1-9]|[1-2][0-9]|30|31)(?:\]\])?/gi, '$1March $3, $2');
str=str.replace(/(\|[ ]*(?:date|archivedate)[ ]*=[ ]*)(?:\[\[)?([1-2][0-9]{3})(?:\]\]-\[\[|-)0?4-(0[1-9]|[1-2][0-9]|30|31)(?:\]\])?/gi, '$1April $3, $2');
str=str.replace(/(\|[ ]*(?:date|archivedate)[ ]*=[ ]*)(?:\[\[)?([1-2][0-9]{3})(?:\]\]-\[\[|-)0?5-(0[1-9]|[1-2][0-9]|30|31)(?:\]\])?/gi, '$1May $3, $2');
str=str.replace(/(\|[ ]*(?:date|archivedate)[ ]*=[ ]*)(?:\[\[)?([1-2][0-9]{3})(?:\]\]-\[\[|-)0?6-(0[1-9]|[1-2][0-9]|30|31)(?:\]\])?/gi, '$1June $3, $2');
str=str.replace(/(\|[ ]*(?:date|archivedate)[ ]*=[ ]*)(?:\[\[)?([1-2][0-9]{3})(?:\]\]-\[\[|-)0?7-(0[1-9]|[1-2][0-9]|30|31)(?:\]\])?/gi, '$1July $3, $2');
str=str.replace(/(\|[ ]*(?:date|archivedate)[ ]*=[ ]*)(?:\[\[)?([1-2][0-9]{3})(?:\]\]-\[\[|-)0?8-(0[1-9]|[1-2][0-9]|30|31)(?:\]\])?/gi, '$1August $3, $2');
str=str.replace(/(\|[ ]*(?:date|archivedate)[ ]*=[ ]*)(?:\[\[)?([1-2][0-9]{3})(?:\]\]-\[\[|-)0?9-(0[1-9]|[1-2][0-9]|30|31)(?:\]\])?/gi, '$1September $3, $2');
str=str.replace(/(\|[ ]*(?:date|archivedate)[ ]*=[ ]*)(?:\[\[)?([1-2][0-9]{3})(?:\]\]-\[\[|-)10-(0[1-9]|[1-2][0-9]|30|31)(?:\]\])?/gi, '$1October $3, $2');
str=str.replace(/(\|[ ]*(?:date|archivedate)[ ]*=[ ]*)(?:\[\[)?([1-2][0-9]{3})(?:\]\]-\[\[|-)11-(0[1-9]|[1-2][0-9]|30|31)(?:\]\])?/gi, '$1November $3, $2');
str=str.replace(/(\|[ ]*(?:date|archivedate)[ ]*=[ ]*)(?:\[\[)?([1-2][0-9]{3})(?:\]\]-\[\[|-)12-(0[1-9]|[1-2][0-9]|30|31)(?:\]\])?/gi, '$1December $3, $2');
 
ohc_protect_dates(editor);
str=str.replace(/(\|[ ]*accessdate[ ]*=[ ]*)(?:\[\[)?([1-2][0-9]{3})(?:\]\]-\[\[|-)0?1-(0[1-9]|[1-2][0-9]|30|31)(?:\]\])?/gi, '$1January $3, $2');
ohc_delink_ISO_to_mdy(editor);
str=str.replace(/(\|[ ]*accessdate[ ]*=[ ]*)(?:\[\[)?([1-2][0-9]{3})(?:\]\]-\[\[|-)0?2-(0[1-9]|[1-2][0-9]|30|31)(?:\]\])?/gi, '$1February $3, $2');
ohc_customize_ISO_to_mdy(editor);
str=str.replace(/(\|[ ]*accessdate[ ]*=[ ]*)(?:\[\[)?([1-2][0-9]{3})(?:\]\]-\[\[|-)0?3-(0[1-9]|[1-2][0-9]|30|31)(?:\]\])?/gi, '$1March $3, $2');
ohc_unprotect_dates(editor);
str=str.replace(/(\|[ ]*accessdate[ ]*=[ ]*)(?:\[\[)?([1-2][0-9]{3})(?:\]\]-\[\[|-)0?4-(0[1-9]|[1-2][0-9]|30|31)(?:\]\])?/gi, '$1April $3, $2');
 
str=str.replace(/(\|[ ]*accessdate[ ]*=[ ]*)(?:\[\[)?([1-2][0-9]{3})(?:\]\]-\[\[|-)0?5-(0[1-9]|[1-2][0-9]|30|31)(?:\]\])?/gi, '$1May $3, $2');
//ohc_MOSNUM_edit_summary(editor);
str=str.replace(/(\|[ ]*accessdate[ ]*=[ ]*)(?:\[\[)?([1-2][0-9]{3})(?:\]\]-\[\[|-)0?6-(0[1-9]|[1-2][0-9]|30|31)(?:\]\])?/gi, '$1June $3, $2');
str=str.replace(/(\|[ ]*accessdate[ ]*=[ ]*)(?:\[\[)?([1-2][0-9]{3})(?:\]\]-\[\[|-)0?7-(0[1-9]|[1-2][0-9]|30|31)(?:\]\])?/gi, '$1July $3, $2');
str=str.replace(/(\|[ ]*accessdate[ ]*=[ ]*)(?:\[\[)?([1-2][0-9]{3})(?:\]\]-\[\[|-)0?8-(0[1-9]|[1-2][0-9]|30|31)(?:\]\])?/gi, '$1August $3, $2');
str=str.replace(/(\|[ ]*accessdate[ ]*=[ ]*)(?:\[\[)?([1-2][0-9]{3})(?:\]\]-\[\[|-)0?9-(0[1-9]|[1-2][0-9]|30|31)(?:\]\])?/gi, '$1September $3, $2');
str=str.replace(/(\|[ ]*accessdate[ ]*=[ ]*)(?:\[\[)?([1-2][0-9]{3})(?:\]\]-\[\[|-)10-(0[1-9]|[1-2][0-9]|30|31)(?:\]\])?/gi, '$1October $3, $2');
str=str.replace(/(\|[ ]*accessdate[ ]*=[ ]*)(?:\[\[)?([1-2][0-9]{3})(?:\]\]-\[\[|-)11-(0[1-9]|[1-2][0-9]|30|31)(?:\]\])?/gi, '$1November $3, $2');
str=str.replace(/(\|[ ]*accessdate[ ]*=[ ]*)(?:\[\[)?([1-2][0-9]{3})(?:\]\]-\[\[|-)12-(0[1-9]|[1-2][0-9]|30|31)(?:\]\])?/gi, '$1December $3, $2');
return str;
}
 
function Ohc_all_dates_to_dmyohc_delink_year_in_X_driver(editor) {
ohc_extend_editor(editor);
Ohc_dates_to_dmy();
 
Ohc_delink_ISO_to_dmy();
ohc_delink_year_in_X(editor);
Ohc_delink_year_in_X();
Ohc_MOSNUM_edit_summary();
}
 
function Ohc_all_dates_to_mdyohc_expand_ref_dates_driver(editor) {
ohc_extend_editor(editor);
Ohc_dates_to_mdy();
 
Ohc_delink_ISO_to_mdy();
ohc_expand_ref_dates(editor);
Ohc_delink_year_in_X();
ohc_protect_dates(editor);
Ohc_MOSNUM_edit_summary();
ohc_unprotect_dates(editor);
ohc_expand_edit_summary(editor);
}
 
function Ohc_body_to_dmyohc_expand_all_dates_driver(editor) {
ohc_extend_editor(editor);
Ohc_dates_to_dmy();
 
Ohc_MOSNUM_edit_summary();
ohc_expand_ref_dates(editor);
ohc_protect_dates(editor);
ohc_expand_all_dates(editor);
ohc_unprotect_dates(editor);
ohc_expand_edit_summary(editor);
}
 
function Ohc_body_to_mdyohc_abbrev_ref_dates_driver(editor) {
ohc_extend_editor(editor);
Ohc_dates_to_mdy();
 
Ohc_MOSNUM_edit_summary();
ohc_protect_dates(editor);
ohc_abbrev_ref_dates(editor);
ohc_unprotect_dates(editor);
ohc_slash_edit_summary(editor);
}
 
function Ohc_ISO_to_dmyohc_UK_slash_dates_driver(editor) {
ohc_extend_editor(editor);
Ohc_delink_ISO_to_dmy();
 
// Ohc_MOSNUM_edit_summary();
ohc_expand_ref_dates(editor);
ohc_protect_dates_slash(editor);
ohc_UK_slash_dates_to_dmy(editor);
ohc_unprotect_dates(editor);
ohc_slash_edit_summary(editor);
}
 
function Ohc_ISO_to_mdyohc_US_slash_dates_driver(editor) {
ohc_extend_editor(editor);
Ohc_delink_ISO_to_mdy();
 
// Ohc_MOSNUM_edit_summary();
ohc_expand_ref_dates(editor);
ohc_protect_dates_slash(editor);
ohc_US_slash_dates_to_mdy(editor);
ohc_unprotect_dates(editor);
ohc_expand_edit_summary(editor);
}
 
// </pre>
addOnloadHook(function () {
if(document.forms.editform) {
addPortletLink('p-tb', 'javascript:Ohc_all_dates_to_dmy()', 'ALL dates to dmy', 'ca-unitfixer', 'Align all dates to dmy', '', '');
addPortletLink('p-tb', 'javascript:Ohc_all_dates_to_mdy()', 'ALL dates to mdy', 'ca-unitfixer', 'Align all dates to mdy', '', '');
addPortletLink('p-tb', 'javascript:Ohc_body_to_dmy()', 'Body dates to dmy', 't-dmy', 'day month', '', '');
addPortletLink('p-tb', 'javascript:Ohc_body_to_mdy()', 'Body dates to mdy', 't-mdy', 'month day', '', '');
addPortletLink('p-tb', 'javascript:Ohc_ISO_to_dmy()', 'ISO to dmy', 't-ISOdmy', 'ISO day month', '', '');
addPortletLink('p-tb', 'javascript:Ohc_ISO_to_mdy()', 'ISO to mdy', 't-ISOmdy', 'ISO month day', '', '');
addPortletLink('p-tb', 'javascript:Ohc_delink_year_in_X()' , 'Del year-in-X dates', 't-yearinX', 'Year in X', '', '');
addPortletLink('p-tb', 'javascript:Ohc_unambiguous_dates()', 'unambiguous dates', 't-slash', 'resolves slash date format', '', '');
addPortletLink('p-tb', 'javascript:Ohc_US_slash_dates()', 'US-slash dates', 't-US', 'US-slash', '', '');
addPortletLink('p-tb', 'javascript:Ohc_UK_slash_dates()', 'UK-slash dates', 't-UK', 'UK-slash', '', '');
}
});