User:Spleodrach/monobook.js/script.js

function delink_ISO { var txt = document.editform.wpTextbox1; //   delink_ISO; txt.value=txt.value.replace(/\[\[(\d{4}-\d\d-\d\d)\]\]/gi, '$1'); txt.value=txt.value.replace(/\[\[(\d{4})\]\]-\[\[(\d\d-\d\d)\]\]/gi, '$1-$2'); txt.value=txt.value.replace(/(\d{4})-\[\[(\d\d-\d\d)\]\]/gi, '$1-$2'); txt.value=txt.value.replace(/\[\[(\d{4})\]\]-(\d\d-\d\d)/gi, '$1-$2'); // Add a tag to the summary box var txt = document.editform.wpSummary; var summary = "Date audit, script-assisted; see mosnum"; if (txt.value.indexOf(summary) == -1) { if (txt.value.match(/[^\*\/\s][^\/\s]?\s*$/)) { txt.value += " | "; }		txt.value += summary; } // Press the diff button to check it   document.editform.wpDiff.click } $(function {    if(document.forms.editform) { //        mw.util.addPortletLink('p-cactions', 'javascript:run_delink_ISO', 'delink ISO', 'ca-unitfixer', 'Fixes some unit formatting', , );    } });

function delink_ISO_to_dmy { var txt = document.editform.wpTextbox1;

txt.value=txt.value.replace(/\[\[(\d{4})-01-(?:0(\d)|([1-3]\d))\]\]/gi, '$2 January $1'); txt.value=txt.value.replace(/\[\[(\d{4})-02-(?:0(\d)|([1-3]\d))\]\]/gi, '$2 February $1'); txt.value=txt.value.replace(/\[\[(\d{4})-03-(?:0(\d)|([1-3]\d))\]\]/gi, '$2 March $1'); txt.value=txt.value.replace(/\[\[(\d{4})-04-(?:0(\d)|([1-3]\d))\]\]/gi, '$2 April $1'); txt.value=txt.value.replace(/\[\[(\d{4})-05-(?:0(\d)|([1-3]\d))\]\]/gi, '$2 May $1'); txt.value=txt.value.replace(/\[\[(\d{4})-06-(?:0(\d)|([1-3]\d))\]\]/gi, '$2 June $1'); txt.value=txt.value.replace(/\[\[(\d{4})-07-(?:0(\d)|([1-3]\d))\]\]/gi, '$2 July $1'); txt.value=txt.value.replace(/\[\[(\d{4})-08-(?:0(\d)|([1-3]\d))\]\]/gi, '$2 August $1'); txt.value=txt.value.replace(/\[\[(\d{4})-09-(?:0(\d)|([1-3]\d))\]\]/gi, '$2 September $1'); txt.value=txt.value.replace(/\[\[(\d{4})-10-(?:0(\d)|([1-3]\d))\]\]/gi, '$2 October $1'); txt.value=txt.value.replace(/\[\[(\d{4})-11-(?:0(\d)|([1-3]\d))\]\]/gi, '$2 November $1'); txt.value=txt.value.replace(/\[\[(\d{4})-12-(?:0(\d)|([1-3]\d))\]\]/gi, '$2 December $1');

txt.value=txt.value.replace(/\[\[(\d{4})\]\]-\[\[01-(?:0(\d)|([1-3]\d))\]\]/gi, '$2 January $1'); txt.value=txt.value.replace(/\[\[(\d{4})\]\]-\[\[02-(?:0(\d)|([1-3]\d))\]\]/gi, '$2 February $1'); txt.value=txt.value.replace(/\[\[(\d{4})\]\]-\[\[03-(?:0(\d)|([1-3]\d))\]\]/gi, '$2 March $1'); txt.value=txt.value.replace(/\[\[(\d{4})\]\]-\[\[04-(?:0(\d)|([1-3]\d))\]\]/gi, '$2 April $1'); txt.value=txt.value.replace(/\[\[(\d{4})\]\]-\[\[05-(?:0(\d)|([1-3]\d))\]\]/gi, '$2 May $1'); txt.value=txt.value.replace(/\[\[(\d{4})\]\]-\[\[06-(?:0(\d)|([1-3]\d))\]\]/gi, '$2 June $1'); txt.value=txt.value.replace(/\[\[(\d{4})\]\]-\[\[07-(?:0(\d)|([1-3]\d))\]\]/gi, '$2 July $1'); txt.value=txt.value.replace(/\[\[(\d{4})\]\]-\[\[08-(?:0(\d)|([1-3]\d))\]\]/gi, '$2 August $1'); txt.value=txt.value.replace(/\[\[(\d{4})\]\]-\[\[09-(?:0(\d)|([1-3]\d))\]\]/gi, '$2 September $1'); txt.value=txt.value.replace(/\[\[(\d{4})\]\]-\[\[10-(?:0(\d)|([1-3]\d))\]\]/gi, '$2 October $1'); txt.value=txt.value.replace(/\[\[(\d{4})\]\]-\[\[11-(?:0(\d)|([1-3]\d))\]\]/gi, '$2 November $1'); txt.value=txt.value.replace(/\[\[(\d{4})\]\]-\[\[12-(?:0(\d)|([1-3]\d))\]\]/gi, '$2 December $1'); }

function delink_ISO_to_mdy { var txt = document.editform.wpTextbox1;

txt.value=txt.value.replace(/\[\[(\d{4})-01-(?:0(\d)|([1-3]\d))\]\]/gi, 'January $2, $1'); txt.value=txt.value.replace(/\[\[(\d{4})-02-(?:0(\d)|([1-3]\d))\]\]/gi, 'February $2, $1'); txt.value=txt.value.replace(/\[\[(\d{4})-03-(?:0(\d)|([1-3]\d))\]\]/gi, 'March $2, $1'); txt.value=txt.value.replace(/\[\[(\d{4})-04-(?:0(\d)|([1-3]\d))\]\]/gi, 'April $2, $1'); txt.value=txt.value.replace(/\[\[(\d{4})-05-(?:0(\d)|([1-3]\d))\]\]/gi, 'May $2, $1'); txt.value=txt.value.replace(/\[\[(\d{4})-06-(?:0(\d)|([1-3]\d))\]\]/gi, 'June $2, $1'); txt.value=txt.value.replace(/\[\[(\d{4})-07-(?:0(\d)|([1-3]\d))\]\]/gi, 'July $2, $1'); txt.value=txt.value.replace(/\[\[(\d{4})-08-(?:0(\d)|([1-3]\d))\]\]/gi, 'August $2, $1'); txt.value=txt.value.replace(/\[\[(\d{4})-09-(?:0(\d)|([1-3]\d))\]\]/gi, 'September $2, $1'); txt.value=txt.value.replace(/\[\[(\d{4})-10-(?:0(\d)|([1-3]\d))\]\]/gi, 'October $2, $1'); txt.value=txt.value.replace(/\[\[(\d{4})-11-(?:0(\d)|([1-3]\d))\]\]/gi, 'November $2, $1'); txt.value=txt.value.replace(/\[\[(\d{4})-12-(?:0(\d)|([1-3]\d))\]\]/gi, 'December $2, $1');

txt.value=txt.value.replace(/\[\[(\d{4})\]\]-\[\[01-(?:0(\d)|([1-3]\d))\]\]/gi, 'January $2, $1'); txt.value=txt.value.replace(/\[\[(\d{4})\]\]-\[\[02-(?:0(\d)|([1-3]\d))\]\]/gi, 'February $2, $1'); txt.value=txt.value.replace(/\[\[(\d{4})\]\]-\[\[03-(?:0(\d)|([1-3]\d))\]\]/gi, 'March $2, $1'); txt.value=txt.value.replace(/\[\[(\d{4})\]\]-\[\[04-(?:0(\d)|([1-3]\d))\]\]/gi, 'April $2, $1'); txt.value=txt.value.replace(/\[\[(\d{4})\]\]-\[\[05-(?:0(\d)|([1-3]\d))\]\]/gi, 'May $2, $1'); txt.value=txt.value.replace(/\[\[(\d{4})\]\]-\[\[06-(?:0(\d)|([1-3]\d))\]\]/gi, 'June $2, $1'); txt.value=txt.value.replace(/\[\[(\d{4})\]\]-\[\[07-(?:0(\d)|([1-3]\d))\]\]/gi, 'July $2, $1'); txt.value=txt.value.replace(/\[\[(\d{4})\]\]-\[\[08-(?:0(\d)|([1-3]\d))\]\]/gi, 'August $2, $1'); txt.value=txt.value.replace(/\[\[(\d{4})\]\]-\[\[09-(?:0(\d)|([1-3]\d))\]\]/gi, 'September $2, $1'); txt.value=txt.value.replace(/\[\[(\d{4})\]\]-\[\[10-(?:0(\d)|([1-3]\d))\]\]/gi, 'October $2, $1'); txt.value=txt.value.replace(/\[\[(\d{4})\]\]-\[\[11-(?:0(\d)|([1-3]\d))\]\]/gi, 'November $2, $1'); txt.value=txt.value.replace(/\[\[(\d{4})\]\]-\[\[12-(?:0(\d)|([1-3]\d))\]\]/gi, 'December $2, $1');

}

function year_in_blah { var txt = document.editform.wpTextbox1;

//Identify surprise or 'Easter egg' diversions linking years to 'year in something' articles. Turn them into year links to be dealt with below txt.value=txt.value.replace(/\[\[\d{1,4}s?\sin\s[^\|]+\|(\d{1,4}s?)\]\]/gi, '\[\[$1\]\]'); }

function part_dates { var txt = document.editform.wpTextbox1;

// century 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\]\]/gi, '$1century'); 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\s(AD|BC|CE|BCE)\]\]/gi, '$1century'); txt.value=txt.value.replace(/\[\[(\d{1,2}(?:st|nd|rd|th)(?:\s|-))century\]\]/gi, '$1century'); txt.value=txt.value.replace(/\[\[(\d{1,2}(?:st|nd|rd|th)(?:\s|-))centuries\]\]/gi, '$1centuries'); txt.value=txt.value.replace(/\[\[\d{1,2}(?:st|nd|rd|th)(?:\s|-)century\|(\d{1,2}(?:st|nd|rd|th))\]\]/gi, '$1'); txt.value=txt.value.replace(/\[\[\d{1,2}(?:st|nd|rd|th)(?:\s|-)century\|(\d{1,2}(?:st|nd|rd|th)(?:\s|-))century\]\]/gi, '$1century'); txt.value=txt.value.replace(/\[\[\d{1,2}(?:st|nd|rd|th)(?:\s|-)century\|(\d{1,2}(?:st|nd|rd|th)(?:\s|-))centuries\]\]/gi, '$1centuries'); txt.value=txt.value.replace(/\[\[(\d{1,2}(?:st|nd|rd|th)(?:\s|-))century\s(AD|BC|CE|BCE)\]\]/gi, '$1century $2'); txt.value=txt.value.replace(/\[\[\d{1,2}(?:st|nd|rd|th)(?:\s|-)century\|(\d{1,2}(?:st|nd|rd|th)(?:\s|-))century\s(AD|BC|CE|BCE)\]\]/gi, '$1century $2'); txt.value=txt.value.replace(/\[\[\d{1,2}(?:st|nd|rd|th)(?:\s|-)century\|(\d{1,2}(?:st|nd|rd|th)(?:\s|-))centuries\s(AD|BC|CE|BCE)\]\]/gi, '$1centuries $2');

//Removed: forcing lower case for 'century' when not linked //century - protect names like '20th Century Fox', '20th Century Picture' '20th Century Limited'. Method is to test for capital letter in next word- undone below //txt.value=txt.value.replace(/(20th)\s(Century)\s([A-Z])/gi, '$1xx$2 $3'); //century - upper case 'C' to lower case //txt.value=txt.value.replace(/(\d(?:st|nd|rd|th)(?:\s|-))Century((?:\s|-)[^A-Z])/g, '$1century$2'); //century- unprotect names //txt.value=txt.value.replace(/(20th)xx(Century)/gi, '$1 $2');

// decades and years txt.value=txt.value.replace(/\[\[(\d{1,4})\'?s\]\]/gi, '$1s'); txt.value=txt.value.replace(/\[\[(\d{1,4})\'?(s)?\s(AD|BC|CE|BCE)\]\]/gi, '$1$2 $3'); txt.value=txt.value.replace(/\[\[\d{1,4}\'?s?\s(?:AD|BC|CE|BCE)\|(\d{1,4})\'?(s)?\]\]/gi, '$1$2'); txt.value=txt.value.replace(/\[\[\d{1,4}\'?s?\s(?:AD|BC|CE|BCE)\|(\d{1,4})\'?(s)?\s(AD|BC|CE|BCE)\]\]/gi, '$1$2 $3'); txt.value=txt.value.replace(/\[\[\d{1,4}\'?s?\|(\d{1,4})\'?(s)?\s(AD|BC|CE|BCE)\]\]/gi, '$1$2 $3'); txt.value=txt.value.replace(/\[\[\d{1,4}\'?s?\|(\d{1,4})\'?(s)?\]\]/gi, '$1$2'); txt.value=txt.value.replace(/\[\[\d\d?(?:st|nd|rd|th)\scentur(?:y|ies)\|(\d{1,4})\'?(s)?\]\]/gi, '$1$2'); txt.value=txt.value.replace(/\[\[\w{5,12}\scentur(?:y|ies)\|(\d{1,4})\'?(s)?\]\]/gi, '$1$2'); // solitary day_numbers txt.value=txt.value.replace(/\[\[(?:January|February|March|April|May|June|July|August|September|October|November|December) \d{1,2}\|(\d{1,2}(?:th|st|nd|rd))\]\]/gi, '$1'); txt.value=txt.value.replace(/\[\[\d{1,2} (?:January|February|March|April|May|June|July|August|September|October|November|December)\|(\d{1,2}(?:th|st|nd|rd))\]\]/gi, '$1'); txt.value=txt.value.replace(/\[\[(\d{1,2}(?:st|nd|rd|th))\]\]/gi, '$1'); //month+day: remove incorrect trailing space txt.value=txt.value.replace(/(\[\[(?:January|February|March|April|May|June|July|August|September|October|November|December)\s\d\d?)\s(\]\])/gi,'$1$2'); //month+year //Identify surprise or 'Easter egg' diversions linking month+years to year articles. Turn them into month+year links to be dealt with below txt.value=txt.value.replace(/\[\[\d{1,4}#[^\|]+\|((?:January|February|March|April|May|June|July|August|September|October|November|December) \d{3,4})\]\]/gi, '\[\[$1\]\]'); txt.value=txt.value.replace(/\[\[((?:January|February|March|April|May|June|July|August|September|October|November|December) \d{3,4})\]\]/gi, '$1');

//year: temporary change to protect accessyear. Undone below at #1 txt.value=txt.value.replace(/(accessyear\s?=\s?)\[\[(\d{1,4})\]\]/gi, '$1xx$2xx'); //Year: temporary change to protext preference dates - y?y?y?. Needed to handle 'year in' piped links txt.value=txt.value.replace(/(\[\[\d\d?\s(?:January|February|March|April|May|June|July|August|September|October|November|December)\]\],?\s?\s?)\[\[(\d{1,4})\]\]y?y?y?/gi,'$1xx$2xx'); txt.value=txt.value.replace(/(\[\[\d\d?\s(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\]\],?\s?\s?)\[\[(\d{1,4})\]\]y?y?y?/g,'$1xx$2xx'); txt.value=txt.value.replace(/(\[\[(?:January|February|March|April|May|June|July|August|September|October|November|December)\s\d\d?\]\],?\s?\s?)\[\[(\d{1,4})\]\]y?y?y?/gi,'$1xx$2xx'); txt.value=txt.value.replace(/(\[\[(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s\d\d?\]\],?\s?\s?)\[\[(\d{1,4})\]\]y?y?y?/g,'$1xx$2xx'); txt.value=txt.value.replace(/\[\[(\d{1,4})\]\]y?y?y?(,?\s?\-?\s?\[\[(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s\d\d?\]\])/g,'xx$1xx$2'); txt.value=txt.value.replace(/\[\[(\d{1,4})\]\]y?y?y?(,?\s?\-?\s?\[\[(?:January|February|March|April|May|June|July|August|September|October|November|December)\s\d\d?\]\])/gi,'xx$1xx$2'); txt.value=txt.value.replace(/\[\[(\d{1,4})\]\]y?y?y?(,?\s?\-?\s?\[\[\d\d?\s(?:January|February|March|April|May|June|July|August|September|October|November|December)\]\])/gi,'xx$1xx$2'); txt.value=txt.value.replace(/\[\[(\d{1,4})\]\]y?y?y?(,?\s?\-?\s?\[\[\d\d\-\d\d\]\]y?y?y?)/gi,'xx$1xx$2');

//year: now remove unprotected linked years txt.value=txt.value.replace(/\[\[(\d{1,4})\]\]/gi, '$1'); //year: #1. Undo temporary change to protect accessyear and date preference dates txt.value=txt.value.replace(/xx(\d{1,4})xx/gi, '\[\[$1\]\]');

//'present' txt.value=txt.value.replace(/\[\[Present \(time\)\|(Present)\]\]/gi, '$1'); txt.value=txt.value.replace(/\[\[(Present)\]\]/gi, '$1');

//Season txt.value=txt.value.replace(/\[\[(spring\s\(season\)|summer|winter|autumn)\]\]/gi, '$1'); txt.value=txt.value.replace(/\[\[spring\s\(season\)\|(spring)\]\]/gi, '$1');

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

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

//month piped to number txt.value=txt.value.replace(/\[\[(?:January|February|March|April|May|June|July|August|September|October|November|December)\|(\d{1,4})\]\]/gi, '$1');

//Month+day_number "March 7th" -> "March 7" txt.value=txt.value.replace(/\[\[(January|February|March|April|May|June|July|August|September|October|November|December) (\d?\d)(?:th|st|nd|rd)\]\]/gi, '\[\[$1 $2\]\]'); txt.value=txt.value.replace(/\[\[((?:January|February|March|April|May|June|July|August|September|October|November|December) \d?\d)\]\](?:th|st|nd|rd)/gi, '\[\[$1\]\]'); txt.value=txt.value.replace(/\[\[(\d?\d)(?:th|st|nd|rd) (January|February|March|April|May|June|July|August|September|October|November|December)\]\]/gi, '\[\[$1 $2\]\]');

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

txt.value=txt.value.replace(/([^\[]{4})\[\[((?:January|February|March|April|May|June|July|August|September|October|November|December) \d?\d)\]\](\s?\-?\s?)\[\[(\d{1,2})\]\]/gi, '$1$2$3$4'); //same again but with ndash instead of hyphen txt.value=txt.value.replace(/([^\[]{4})\[\[((?:January|February|March|April|May|June|July|August|September|October|November|December) \d?\d)\]\](\s?&[nm]dash;\s?)\[\[(\d{1,2})\]\]/gi, '$1$2$3$4'); //same again but with slash instead of hyphen txt.value=txt.value.replace(/([^\[]{4})\[\[((?:January|February|March|April|May|June|July|August|September|October|November|December) \d?\d)\]\](\/)\[\[(\d{1,2})\]\]/gi, '$1$2$3$4');

txt.value=txt.value.replace(/([^\[]{4})\[\[(\d?\d) (?:January|February|March|April|May|June|July|August|September|October|November|December)\]\](\s?\-?\s?)\[\[(?:January|February|March|April|May|June|July|August|September|October|November|December) \d{1,2}\|(\d{1,2})\]\]/gi, '$1$2$3$4'); //same again but with ndash instead of hyphen txt.value=txt.value.replace(/([^\[]{4})\[\[(\d?\d) (?:January|February|March|April|May|June|July|August|September|October|November|December)\]\](\s?&[nm]dash;\s?)\[\[(?:January|February|March|April|May|June|July|August|September|October|November|December) \d{1,2}\|(\d{1,2})\]\]/gi, '$1$2$3$4'); //same again but with slash instead of hyphen txt.value=txt.value.replace(/([^\[]{4})\[\[(\d?\d) (?:January|February|March|April|May|June|July|August|September|October|November|December)\]\](\/)\[\[(?:January|February|March|April|May|June|July|August|September|October|November|December) \d{1,2}\|(\d{1,2})\]\]/gi, '$1$2$3$4');

txt.value=txt.value.replace(/([^\[]{4})\[\[(\d?\d) (?:January|February|March|April|May|June|July|August|September|October|November|December)\]\](\s?\-?\s?)\[\[(\d{1,2})\]\]/gi, '$1$2$3$4'); //same again but with ndash instead of hyphen txt.value=txt.value.replace(/([^\[]{4})\[\[(\d?\d) (?:January|February|March|April|May|June|July|August|September|October|November|December)\]\](\s?&[nm]dash;\s?)\[\[(\d{1,2})\]\]/gi, '$1$2$3$4'); //same again but with slash instead of hyphen txt.value=txt.value.replace(/([^\[]{4})\[\[(\d?\d) (?:January|February|March|April|May|June|July|August|September|October|November|December)\]\](\/)\[\[(\d{1,2})\]\]/gi, '$1$2$3$4');

txt.value=txt.value.replace(/\[\[(?:January|February|March|April|May|June|July|August|September|October|November|December) \d{1,2}\|(\d{1,2})\]\]/gi, '$1'); txt.value=txt.value.replace(/\[\[\d{1,2} (?:January|February|March|April|May|June|July|August|September|October|November|December)\|(\d{1,2})\]\]/gi, '$1');

txt.value=txt.value.replace(/\[\[(?:January|February|March|April|May|June|July|August|September|October|November|December)\s\d{1,2}\|((?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s\d{1,2})\]\]/g, '$1'); //month+day piped into month+day or vice versa txt.value=txt.value.replace(/\[\[\d{1,2}\s(?:January|February|March|April|May|June|July|August|September|October|November|December)\|((?:January|February|March|April|May|June|July|August|September|October|November|December)\s\d{1,2})\]\]/gi, '$1'); txt.value=txt.value.replace(/\[\[(?:January|February|March|April|May|June|July|August|September|October|November|December)\s\d{1,2}\|(\d{1,2}\s(?:January|February|March|April|May|June|July|August|September|October|November|December))\]\]/gi, '$1');

// days of the week in full. Optional plurals txt.value=txt.value.replace(/\[\[(Mondays?|Tuesdays?|Wednesdays?|Thursdays?|Fridays?|Saturdays?|Sundays?)\]\]/gi, '$1'); // days of the week abbreviated. Leave out 'Sun' as potentially valid link to the Sun. Leave out 'SAT' in upper case as potential link to 'Scholastic achievement/aptitude test'. txt.value=txt.value.replace(/\[\[(Mon|Tue|Tues|Wed|Thu|Thur|Thurs|Fri)\]\]/gi, '$1'); txt.value=txt.value.replace(/\[\[(Sat)\]\]/g, '$1'); txt.value=txt.value.replace(/\[\[Mondays?\|(Mondays?|Mon)\]\]/gi, '$1'); txt.value=txt.value.replace(/\[\[Tuesdays?\|(Tuesdays?|Tues?)\]\]/gi, '$1'); txt.value=txt.value.replace(/\[\[Wednesdays?\|(Wednesdays?|Wed)\]\]/gi, '$1'); txt.value=txt.value.replace(/\[\[Thursdays?\|(Thursdays?|Thur?)\]\]/gi, '$1'); txt.value=txt.value.replace(/\[\[Fridays?\|(Fridays?|Fri)\]\]/gi, '$1'); txt.value=txt.value.replace(/\[\[Saturdays?\|(Saturdays?|Sat)\]\]/gi, '$1'); txt.value=txt.value.replace(/\[\[Sundays?\|(Sundays?|Sun)\]\]/gi, '$1');

//4 digit years piped into 2 txt.value=txt.value.replace(/\[\[\d{1,4}\|(\d{1,2})\]\]/gi, '$1'); }

function formatgeneral { var txt = document.editform.wpTextbox1;

//remove flagicons from birth and death txt.value=txt.value.replace(/(birth\s?=\s?)\{\{flagicon\|[^\}]+\}\}/gi, '$1'); txt.value=txt.value.replace(/(death\s?=\s?)\{\{flagicon\|[^\}]+\}\}/gi, '$1'); txt.value=txt.value.replace(/(birth_?place\s?=\s?)\{\{flagicon\|[^\}]+\}\}/gi, '$1'); txt.value=txt.value.replace(/(death_?place\s?=\s?)\{\{flagicon\|[^\}]+\}\}/gi, '$1');

//symbol for 'times' txt.value=txt.value.replace(/&times;/gi, '×');

//symbol for superscript 2 and 3 //txt.value=txt.value.replace(/ 2<\/sup>/gi, '²'); //txt.value=txt.value.replace(/ 3<\/sup>/gi, '³');

//Attempt to deal with naval infobox txt.value=txt.value.replace(/General\sCharacteristics/g, 'General characteristics');

//turn letter 'x' into symbol '×' txt.value=txt.value.replace(/(\d)\sx\s(\d{1,3})\sin\s\(/gi, '$1 × $2 in ('); txt.value=txt.value.replace(/(\d)\sx\s(\d{1,3})\sinch\s/gi, '$1 × $2 inch ');

// Convert degree symbols into ° symbol, ensure preceding space txt.value=txt.value.replace(/&deg;/g, '°'); txt.value=txt.value.replace(/º/g, '°');

//aviation specifications: protect 'main=' and 'alt=' - undone below txt.value=txt.value.replace(/((?:main|alt)\s?=\s?)(\d)/gi, '$1xx$2');

// Celsius spelling errors txt.value=txt.value.replace(/celsius/gi, 'Celsius'); txt.value=txt.value.replace(/celcius/gi, 'Celsius'); //Fix common naming error (be careful with this one) txt.value=txt.value.replace(/centigrade/gi, 'Celsius'); //Celsius or Fahrenheit txt.value=txt.value.replace(/(\d) (?:°|deg|degree|degrees) ([CF]\W)/g, '$1 °$2'); txt.value=txt.value.replace(/(\d)(?:°|deg|degree|degrees) ([CF]\W)/g, '$1 °$2'); txt.value=txt.value.replace(/(\d) (?:°|deg|degree|degrees)([CF]\W)/g, '$1 °$2'); txt.value=txt.value.replace(/(\d)(?:\s|)(?:°|deg|degree|degrees)(?:\s|)([CF]\W)/g, '$1 °$2'); txt.value=txt.value.replace(/(\d) (\[\[Celsius|°C\]\])/gi, '$1 $2'); txt.value=txt.value.replace(/(\d)(?:\s|)(\[\[Celsius|°C\]\])/gi, '$1 $2'); txt.value=txt.value.replace(/(\d) (\[\[Fahrenheit|°F\]\])/gi, '$1 $2'); txt.value=txt.value.replace(/(\d)(?:\s|)(\[\[Fahrenheit|°F\]\])/gi, '$1 $2'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(-?\d[\d,\.]*)(?:\s|-| |)°?F([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1\{\{convert|$2|°F|°C|abbr=on\}\}$3'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(-?\d[\d,\.]*)(?:\s|-| |)(?:deg|degree|degrees)(?:\s|-| |)Fahrenheit([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|°F|°C\}\}$3');

// Convert &sup to superscript txt.value=txt.value.replace(/&sup2;/g, '²'); txt.value=txt.value.replace(/&sup3;/g, '³');

//metre //delink this common unit txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-|)\[\[(metres|meters|metre|meter)\]\]([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1$2 $3$4'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-|)\[\[(metre|meter)\]\]s([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1$2 $3s$4'); //space before 'm' only when lower case. Check for dollars and pounds to avoid 'm' used for millions in money. txt.value=txt.value.replace(/(\(\d[\d,\.]*)(?:\s|-|)m([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1 m$2'); //convert 'metres' to 'm' when in parentheses txt.value=txt.value.replace(/(\(\d[\d,\.]*)(?:\s|-|)(?:metres|meters|metre|meter)(\))/g, '$1 m$2'); txt.value=txt.value.replace(/(\(\d[\d,\.]*) (?:metres|meters|metre|meter)(\))/g, '$1 m$2'); txt.value=txt.value.replace(/({convert\|\d+\|(?:m|ft)[^\}]*)\|lk=(?:on|in|out)/g, '$1');

//metre per second txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-|)(?:m\/second|m\/sec)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1$2 m/s$3'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*) (?:m\/second|m\/sec)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1$2 m/s$3'); txt.value=txt.value.replace(/({convert\|\d+\|(?:m\s|ft\s)[^\}]*)\|lk=(?:on|in|out)/g, '$1');

//square metre txt.value=txt.value.replace(/(\d)(?:\s|-| |)sq(?:\s|\.\s|-| )m([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 m²$2'); txt.value=txt.value.replace(/({convert\|\d+\|(?:m2|sqft)[^\}]*)\|lk=(?:on|in|out)/g, '$1');

// millimetre txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-|)mm([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1$2 mm$3');

// centimetre, cubic centimetre txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-|)(cm|cc)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1$2 $3$4');

// kilometre //delink this common unit txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-|)\[\[(kilometres|kilometers|kilometre|kilometer)\]\]([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1$2 $3$4'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*) \[\[(kilometres|kilometers|kilometre|kilometer)\]\]([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1$2 $3$4'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-|)\[\[(?:kilometres?|kilometers?)\|(km)\]\]([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1$2 $3$4'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*) \[\[(?:kilometres?|kilometers?)\|(km)\]\]([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1$2 $3$4'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-|)kms?([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1$2 km$3'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*) kms?([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1$2 km$3'); txt.value=txt.value.replace(/({convert\|\d+\|(?:mi|km)[^\}]*)\|lk=(?:on|in|out)/g, '$1');

//square kilometre txt.value=txt.value.replace(/(\d)(\s|-| )\[\[km²\]\]/gi, '$1$2km²'); txt.value=txt.value.replace(/(\d)\s?sq\.?(?:\s|-| |)kms?(\s|\.)/gi, '$1 km²$2'); txt.value=txt.value.replace(/({convert\|\d+)00\|ha\|\d(\||})/g, '$1|km2$2'); txt.value=txt.value.replace(/({convert\|\d+)00\|ha/g, '$1|km2'); txt.value=txt.value.replace(/({convert\|\d+)(\d)0\|ha\|\d(\||})/g, '$1.$2|km2$2'); txt.value=txt.value.replace(/({convert\|\d+)(\d)0\|ha/g, '$1.$2|km2'); txt.value=txt.value.replace(/({convert\|\d+)(\d\d)\|ha\|\d(\||})/g, '$1.$2|km2$2'); txt.value=txt.value.replace(/({convert\|\d+)(\d\d)\|ha/g, '$1.$2|km2'); txt.value=txt.value.replace(/({convert\|\d+\|sqmi\|)ha\|\d(\||})/g, '$1km2$2'); txt.value=txt.value.replace(/({convert\|\d+\|sqmi\|)ha/g, '$1km2'); txt.value=txt.value.replace(/({convert\|\d\d\d+\|acre\|)ha\|\d(\||})/g, '$1km2$2'); txt.value=txt.value.replace(/({convert\|\d{\d\d+\|acre\|)ha/g, '$1km2'); txt.value=txt.value.replace(/({convert\|\d\d\d+\|acre)}/g, '$1|km2}'); txt.value=txt.value.replace(/({convert\|\d(?:\.\d+|)\|acre)\|ha\|\d(\||})/g, '$1|m2$2'); txt.value=txt.value.replace(/({convert\|\d(?:\.\d+|)\|acre)\|ha/g, '$1|m2'); txt.value=txt.value.replace(/({convert\|\d(?:\.\d+|)\|acre)}/g, '$1|m2}'); txt.value=txt.value.replace(/({convert\|[^\}]*(?:km2|sqmi)[^\}]*)\|lk=(?:on|in|out)/g, '$1');

//kilometre per second txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-|)(?:km\/second|km\/sec)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1$2 km/s$3'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*) (?:km\/second|km\/sec)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1$2 km/s$3');

// kilometre per hour txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-|)(?:km\/hr|km\/ph|kph|kmph|kmh)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1$2 km/h$3'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*) (?:km\/hr|km\/ph|kph|kmph|kmh)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1$2 km/h$3'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-|)\[\[(?:km\/hr|km\/ph|kph|kmph|kmh)\]\]([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1$2 km/h$3'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*) \[\[(?:km\/hr|km\/ph|kph|kmph|kmh)\]\]([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1$2 km/h$3');

//millilitre txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-|)(ml)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1$2 $3$4');

// ensure spaces and correct case in kilowatt txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-|)kW([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1$2 kW$3');

// ensure spaces and correct case in hertz txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-|)Hz([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1$2 Hz$3'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-|)kHz([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1$2 kHz$3'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-|)GHz([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1$2 GHz$3'); // ensure spaces in megahertz. Must be upper case to avoid clashing with millihertz txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-|)MHz([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1$2 MHz$3');

// frames per second txt.value=txt.value.replace(/frames\/s([:;,\.?!]?\s[^\d\(\)\/\\])/gi, 'frame/s$1');

// kilogram txt.value=txt.value.replace(/kilogrammes/gi, 'kilograms'); txt.value=txt.value.replace(/kilogramme/gi, 'kilogram'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-|)\[\[(kilograms?)\]\]([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1$2 $3$4'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*) \[\[(kilograms?)\]\]([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1$2 $3$4'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-|)grammes([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1$2 grams$3'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-|)gramme([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1$2 gram$3'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-|)(?:kgs?|\[\[kg\]\])([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1$2 kg$3'); txt.value=txt.value.replace(/({convert\|\d+\|(?:kg|lb)[^\}]*)\|lk=(?:on|in|out)/g, '$1');

//foot //convert 'foot' to 'ft' when in parentheses txt.value=txt.value.replace(/(\(\d[\d,\.]*)(?:\s|-|)(?:feet|foot)(\))/g, '$1 ft$2'); txt.value=txt.value.replace(/(\(\d[\d,\.]*) (?:feet|foot)(\))/g, '$1 ft$2');

//remove trailing period when in parentheses txt.value=txt.value.replace(/(\(\d[\d,\.]*)(?:\s|-|)ft\.(\))/g, '$1 ft$2'); txt.value=txt.value.replace(/(\(\d[\d,\.]*) ft\.(\))/g, '$1 ft$2');

// square foot //convert 'sq foot' to 'sq ft' txt.value=txt.value.replace(/(\d)(\s|-)sq\.?(\s|-|)(feet|foot|ft)/gi, '$1 sq ft'); txt.value=txt.value.replace(/(\d) sq\.? (feet|foot|ft)/gi, '$1 sq ft'); //convert 'square ft' to 'sq ft' txt.value=txt.value.replace(/(\d)(\s|-)square(\s|-)ft/gi, '$1 sq ft'); txt.value=txt.value.replace(/(\d) square ft/gi, '$1 sq ft'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-| |)sq(?:\s|-| |)ft([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|sqft|m2|abbr=on\}\}$3'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-| |)square(?:\s|-| |)feet([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|sqft|m2\}\}$3'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-| |)square(?:\s|-| |)foot([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|sqft|m2|sing=on\}\}$3'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]+)(?:\s|-| |)thousand(?:\s|-| |)(?:sq|square)\.?(?:\s|-| |)ft([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2000|sqft|m2|abbr=on\}\}$3'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]+)(?:\s|-| |)thousand(?:\s|-| |)(?:sq|square)\.?(?:\s|-| |)feet([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2000|sqft|m2\}\}$3'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]+)(?:\s|-| |)thousand(?:\s|-| |)(?:sq|square)\.?(?:\s|-| |)foot([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2000|sqft|m2|sing=on\}\}$3'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]+)(?:\s|-| |)million(?:\s|-| |)(?:sq|square)\.?(?:\s|-| |)ft([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2000000|sqft|m2|abbr=on\}\}$3'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]+)(?:\s|-| |)million(?:\s|-| |)(?:sq|square)\.?(?:\s|-| |)feet([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2000000|sqft|m2\}\}$3'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]+)(?:\s|-| |)million(?:\s|-| |)(?:sq|square)\.?(?:\s|-| |)foot([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2000000|sqft|m2|sing=on\}\}$3'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]+)\.(\d)(?:\s|-| |)million(?:\s|-| |)(?:sq|square)\.?(?:\s|-| |)ft([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2$300000|sqft|m2|abbr=on\}\}$4'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]+)\.(\d)(?:\s|-| |)million(?:\s|-| |)(?:sq|square)\.?(?:\s|-| |)feet([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2$300000|sqft|m2\}\}$4'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]+)\.(\d)(?:\s|-| |)million(?:\s|-| |)(?:sq|square)\.?(?:\s|-| |)foot([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2$300000|sqft|m2|sing=on\}\}$4'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]+)\.(\d\d)(?:\s|-| |)million(?:\s|-| |)(?:sq|square)\.?(?:\s|-| |)ft([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2$30000|sqft|m2|abbr=on\}\}$4'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]+)\.(\d\d)(?:\s|-| |)million(?:\s|-| |)(?:sq|square)\.?(?:\s|-| |)feet([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2$30000|sqft|m2\}\}$4'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]+)\.(\d\d)(?:\s|-| |)million(?:\s|-| |)(?:sq|square)\.?(?:\s|-| |)foot([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2$30000|sqft|m2|sing=on\}\}$4');

//feet per second txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-|)(?:ft\/second|ft\/sec)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1$2 ft/s$3'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*) (?:ft\/second|ft\/sec)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1$2 ft/s$3'); //feet per second:plural txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-| |)feet\sper\ssecond([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|ft/s|m/s\}\}$3'); //feet per second:singular txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-| |)foot\sper\ssecond([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|ft/s|m/s|sing=on\}\}$3'); //feet per second:abbreviated txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-| |)ft\/s([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|ft/s|m/s|abbr=on\}\}$3');

// foot and inch txt.value=txt.value.replace(/(ength[.]{1,3})(\d{1,4})\s?['’]\s?(\d{1,3})\s?["”]/gi, '$1$2 ft $3 in'); txt.value=txt.value.replace(/(idth[.]{1,3})(\d{1,4})\s?['’]\s?(\d{1,3})\s?["”]/gi, '$1$2 ft $3 in'); txt.value=txt.value.replace(/([\(\|:]\s?\d{1,4})\s?['’]\s?(\d{1,3})\s?["”]([^NESW])/g, '$1 ft $2 in$3'); txt.value=txt.value.replace(/(\d)\s?ft\s?(\d{1,3})\s?in/gi, '$1 ft $2 in');

// yard txt.value=txt.value.replace(/(\d)(?:\s|-| |)yds?([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 yd$2'); txt.value=txt.value.replace(/(\d)(?:\s|-| |)sq\.?\s?yds?([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 sq yd$2'); txt.value=txt.value.replace(/yd\.\)/gi, 'yd)'); //yards: plural txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-| |)(?:yards|\[\[yard\]\]s|\[\[yards\]\])([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|yd|m\}\}$3'); //yards: singular txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-| |)(?:yard|\[\[yard\]\])([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|yd|m|sing=on\}\}$3'); //yards: abbreviated txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-| |)yd([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|yd|m|abbr=on\}\}$3'); //yards: in full txt.value=txt.value.replace(/([^y]\sone(?:\s|-| |)yards?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (1 m)$2'); txt.value=txt.value.replace(/([^y]\stwo(?:\s|-| |)yards?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (2 m)$2'); txt.value=txt.value.replace(/([^y]\sthree(?:\s|-| |)yards?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (3 m)$2'); txt.value=txt.value.replace(/([^y]\sfour(?:\s|-| |)yards?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (4 m)$2'); txt.value=txt.value.replace(/([^y]\sfive(?:\s|-| |)yards?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (5 m)$2'); txt.value=txt.value.replace(/([^y]\ssix(?:\s|-| |)yards?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (5 m)$2'); txt.value=txt.value.replace(/([^y]\sseven(?:\s|-| |)yards?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (6 m)$2'); txt.value=txt.value.replace(/([^y]\seight(?:\s|-| |)yards?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (7 m)$2'); txt.value=txt.value.replace(/([^y]\snine(?:\s|-| |)yards?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (8 m)$2'); txt.value=txt.value.replace(/([^y]\sten(?:\s|-| |)yards?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (9 m)$2'); txt.value=txt.value.replace(/([^y]\seleven(?:\s|-| |)yards?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (10 m)$2'); txt.value=txt.value.replace(/([^y]\stwelve(?:\s|-| |)yards?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (11 m)$2'); txt.value=txt.value.replace(/([^y]\sthirteen(?:\s|-| |)yards?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (12 m)$2'); txt.value=txt.value.replace(/([^y]\sfourteen(?:\s|-| |)yards?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (13 m)$2'); txt.value=txt.value.replace(/([^y]\sfifteen(?:\s|-| |)yards?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (14 m)$2'); txt.value=txt.value.replace(/([^y]\ssixteen(?:\s|-| |)yards?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (15 m)$2'); txt.value=txt.value.replace(/([^y]\sseventeen(?:\s|-| |)yards?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (16 m)$2'); txt.value=txt.value.replace(/([^y]\seighteen(?:\s|-| |)yards?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (16 m)$2'); txt.value=txt.value.replace(/([^y]\snineteen(?:\s|-| |)yards?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (17 m)$2'); txt.value=txt.value.replace(/([^y]\stwenty(?:\s|-| |)yards?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (18 m)$2');

// knot txt.value=txt.value.replace(/(\d)(\s|-| )(?:kts|kt|knt)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1$2knots$3'); txt.value=txt.value.replace(/\[knot\s\(unit\)\|/gi, '[knot (speed)|'); txt.value=txt.value.replace(/\[\[kts\]\]/gi, 'knots'); txt.value=txt.value.replace(/\|kts\]\]/gi, '|knots]]');

//nautical mile - rename 'miles' as 'nautical miles' when followed by knots or conversion code txt.value=txt.value.replace(/(\d)(?:\s|-| |)miles\s(?:at|@)\s([\d\.]{1,9}(?:\s|-| |)knots|\{\{convert)/gi, '$1 nautical miles at $2'); txt.value=txt.value.replace(/(\d)(\s|-| )(?:mi|nm|nmi)\s(?:at|@)\s([\d\.]{1,9}(?:\s|-| |)knots|\{\{convert)/gi, '$1$2nmi at $3'); //nautical mile: plural unlinked txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-| |)nautical(?:\s|-| |)miles([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|nmi|km\}\}$3'); //nautical mile: plural linked with 's' inside link txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-| |)\[\[nautical(?:\s|-| |)miles\]\]([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|nmi|km\}\}$3'); //nautical mile: plural linked with 's' outside link txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-| |)\[\[nautical(?:\s|-| |)mile\]\]s([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|nmi|km\}\}$3'); //nautical mile: singular unlinked txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-| |)nautical(?:\s|-| |)mile([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|nmi|km|sing=on\}\}$3'); //nautical mile: singular linked txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-| |)\[\[nautical(?:\s|-| |)mile\]\]([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|nmi|km|sing=on\}\}$3'); //nautical mile: abbreviated txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-| |)(?:\[\[nautical\smile\|nmi?\]\]|nmi)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|nmi|km|abbr=on\}\}$3'); //nautical mile: in full txt.value=txt.value.replace(/([^y]\sone(?:\s|-| |)nautical(?:\s|-| |)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (1.9 km)$2'); txt.value=txt.value.replace(/([^y]\stwo(?:\s|-| |)nautical(?:\s|-| |)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (4 km)$2'); txt.value=txt.value.replace(/([^y]\sthree(?:\s|-| |)nautical(?:\s|-| |)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (6 km)$2'); txt.value=txt.value.replace(/([^y]\sfour(?:\s|-| |)nautical(?:\s|-| |)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (7 km)$2'); txt.value=txt.value.replace(/([^y]\sfive(?:\s|-| |)nautical(?:\s|-| |)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (9 km)$2'); txt.value=txt.value.replace(/([^y]\ssix(?:\s|-| |)nautical(?:\s|-| |)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (11 km)$2'); txt.value=txt.value.replace(/([^y]\sseven(?:\s|-| |)nautical(?:\s|-| |)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (13 km)$2'); txt.value=txt.value.replace(/([^y]\seight(?:\s|-| |)nautical(?:\s|-| |)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (15 km)$2'); txt.value=txt.value.replace(/([^y]\snine(?:\s|-| |)nautical(?:\s|-| |)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (17 km)$2'); txt.value=txt.value.replace(/([^y]\sten(?:\s|-| |)nautical(?:\s|-| |)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (19 km)$2'); txt.value=txt.value.replace(/([^y]\seleven(?:\s|-| |)nautical(?:\s|-| |)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (20 km)$2'); txt.value=txt.value.replace(/([^y]\stwelve(?:\s|-| |)nautical(?:\s|-| |)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (22 km)$2'); txt.value=txt.value.replace(/([^y]\sthirteen(?:\s|-| |)nautical(?:\s|-| |)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (24 km)$2'); txt.value=txt.value.replace(/([^y]\sfourteen(?:\s|-| |)nautical(?:\s|-| |)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (26 km)$2'); txt.value=txt.value.replace(/([^y]\sfifteen(?:\s|-| |)nautical(?:\s|-| |)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (28 km)$2'); txt.value=txt.value.replace(/([^y]\ssixteen(?:\s|-| |)nautical(?:\s|-| |)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (30 km)$2'); txt.value=txt.value.replace(/([^y]\sseventeen(?:\s|-| |)nautical(?:\s|-| |)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (31 km)$2'); txt.value=txt.value.replace(/([^y]\seighteen(?:\s|-| |)nautical(?:\s|-| |)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (33 km)$2'); txt.value=txt.value.replace(/([^y]\snineteen(?:\s|-| |)nautical(?:\s|-| |)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (35 km)$2'); txt.value=txt.value.replace(/([^y]\stwenty(?:\s|-| |)nautical(?:\s|-| |)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (37 km)$2');

//knot - plural txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-| |)(?:knots|\[\[knot\s\(speed\)\|(?:knots\]\]|knot\]\]s|kts\]\]|kt\]\]s))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|kn|km/h\}\}$3'); //knot - singular txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-| |)(?:knot|\[\[knot\s\(speed\)\|(?:knot|kt|kn)\]\])([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|kn|km/h|sing=on\}\}$3'); //knot - abbreviation txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-| |)(?:kts?|\[\[knot\s\(speed\)\|(?:kt|kn)\]\])([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|kn|km/h|abbr=on\}\}$3');

//mile - delink this common unit txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-|)\[\[(miles?)\]\]([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1$2 $3$4'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*) \[\[(miles?)\]\]([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1$2 $3$4');

//mile - lower case to avoid proper names like 'Five Mile Road' //mile - protect 'miles per hour' - undone below txt.value=txt.value.replace(/(miles?)\s(per)/gi, '$1xx$2'); //miles: plural txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-| |)(?:miles|\[\[miles\]\]|\[\[mile\]\]s)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1\{\{convert|$2|mi|km\}\}$3'); //miles: singular txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-| |)(?:mile|\[\[mile\]\])([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1\{\{convert|$2|mi|km|sing=on\}\}$3'); //miles: abbreviated txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-| |)mi([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1\{\{convert|$2|mi|km|abbr=on\}\}$3'); //miles: in full txt.value=txt.value.replace(/([^y]\sone(?:\s|-| |)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1 (1.6 km)$2'); txt.value=txt.value.replace(/([^y]\stwo(?:\s|-| |)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1 (3 km)$2'); txt.value=txt.value.replace(/([^y]\sthree(?:\s|-| |)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1 (5 km)$2'); txt.value=txt.value.replace(/([^y]\sfour(?:\s|-| |)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1 (6 km)$2'); txt.value=txt.value.replace(/([^y]\sfive(?:\s|-| |)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1 (8 km)$2'); txt.value=txt.value.replace(/([^y]\ssix(?:\s|-| |)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1 (10 km)$2'); txt.value=txt.value.replace(/([^y]\sseven(?:\s|-| |)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1 (11 km)$2'); txt.value=txt.value.replace(/([^y]\seight(?:\s|-| |)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1 (13 km)$2'); txt.value=txt.value.replace(/([^y]\snine(?:\s|-| |)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1 (14 km)$2'); txt.value=txt.value.replace(/([^y]\sten(?:\s|-| |)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1 (16 km)$2'); txt.value=txt.value.replace(/([^y]\seleven(?:\s|-| |)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1 (18 km)$2'); txt.value=txt.value.replace(/([^y]\stwelve(?:\s|-| |)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1 (19 km)$2'); txt.value=txt.value.replace(/([^y]\sthirteen(?:\s|-| |)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1 (19 km)$2'); txt.value=txt.value.replace(/([^y]\sfourteen(?:\s|-| |)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1 (21 km)$2'); txt.value=txt.value.replace(/([^y]\sfifteen(?:\s|-| |)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1 (24 km)$2'); txt.value=txt.value.replace(/([^y]\sixteen(?:\s|-| |)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1 (26 km)$2'); txt.value=txt.value.replace(/([^y]\sseventeen(?:\s|-| |)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1 (27 km)$2'); txt.value=txt.value.replace(/([^y]\seighteen(?:\s|-| |)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1 (29 km)$2'); txt.value=txt.value.replace(/([^y]\snineteen(?:\s|-| |)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1 (30 km)$2'); txt.value=txt.value.replace(/([^y]\stwenty(?:\s|-| |)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1 (32 km)$2');

//mile - unprotect 'miles per hour' txt.value=txt.value.replace(/(miles?)xx(per)/gi, '$1 $2');

//mile per hour txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-| |)m\.?p\.?h([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1\{\{convert|$2|mi/h|km/h|abbr=on\}\}$3');

// square mile txt.value=txt.value.replace(/(\d)(?:\s|-)sq(?:\s|\.\s|-)mi([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 sq mi$2'); txt.value=txt.value.replace(/\[\[(square\smile)\]\]/gi, '$1'); txt.value=txt.value.replace(/\[\[square\smile\|(sq\smi)\]\]/gi, '$1'); txt.value=txt.value.replace(/(sq)(?:\s|-| |)(mile)/gi, '$1uare $2'); // square mile:plural txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-| |)square(?:\s|-| |)miles([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|sqmi|km2\}\}$3'); // square mile:singular txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-| |)square(?:\s|-| |)mile([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|sqmi|km2|sing=on\}\}$3'); // square mile:abbreviated txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-| |)sq(?:\s|-| |)mi([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|sqmi|km2|abbr=on\}\}$3');

//acre foot:plural txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]\d\d+[\d,\.]*)(?:\s|-| |)acre(?:\s|-| |)feet([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1\{\{convert|$2|acre feet\}\}$3'); //acre foot:singular txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]\d\d+[\d,\.]*)(?:\s|-| |)acre(?:\s|-| |)foot([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1\{\{convert|$2|acre feet|sing=on\}\}$3'); //acre foot:abbreviation txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]\d\d+[\d,\.]*)(?:\s|-| |)(?:acre|ac\.?)(?:\s|-| |)(?:foot|feet|ft)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1\{\{convert|$2|acre ft|abbr=on\}\}$3');

//acre //acres - temporary change to protect acre feet. changed below txt.value=txt.value.replace(/(acre.feet)/gi, 'xtempx$1ytempy'); txt.value=txt.value.replace(/(\d)-(acre)/gi, '$1 $2'); txt.value=txt.value.replace(/(\d)(?:\s|-| |)surface(?:\s|-| |)acre/gi, '$1 acre'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]+)(?:\s|-| |)thousand(?:\s|-| |)(?:acres|\[\[acres\]\]|\[\[acre\]\]s)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2000|acre|km2\}\}$3'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]+)(?:\s|-| |)thousand(?:\s|-| |)(?:acre|\[\[acre\]\])([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2000|acre|km2|sing=on\}\}$3'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]+)(?:\s|-| |)million(?:\s|-| |)(?:acres|\[\[acres\]\]|\[\[acre\]\]s)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|e6acre|km2\}\}$3'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]+)(?:\s|-| |)million(?:\s|-| |)(?:acre|\[\[acre\]\])([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|e6acre|km2|sing=on\}\}$3'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]+)\.(\d)(?:\s|-| |)million(?:\s|-| |)(?:acres|\[\[acres\]\]|\[\[acre\]\]s)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2$300000|acre|km2\}\}$4'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]+)\.(\d)(?:\s|-| |)million(?:\s|-| |)(?:acre|\[\[acre\]\])([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2$300000|acre|km2|sing=on\}\}$4'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]+)\.(\d\d)(?:\s|-| |)million(?:\s|-| |)(?:acres|\[\[acres\]\]|\[\[acre\]\]s)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2$30000|acre|km2\}\}$4'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]+)\.(\d\d)(?:\s|-| |)million(?:\s|-| |)(?:acre|\[\[acre\]\])([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2$30000|acre|km2|sing=on\}\}$4'); txt.value=txt.value.replace(/([^y]\sone(?:\s|-| |)million(?:\s|-| |)acres?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (4,000 km²)$2'); txt.value=txt.value.replace(/(\sa(?:\s|-| |)million(?:\s|-| |)acres?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (4,000 km²)$2'); txt.value=txt.value.replace(/([^y]\stwo(?:\s|-| |)million(?:\s|-| |)acres?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (8,000 km²)$2'); txt.value=txt.value.replace(/([^y]\sthree(?:\s|-| |)million(?:\s|-| |)acres?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (12,000 km²)$2'); txt.value=txt.value.replace(/([^y]\sfour(?:\s|-| |)million(?:\s|-| |)acres?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (16,000 km²)$2'); txt.value=txt.value.replace(/([^y]\sfive(?:\s|-| |)million(?:\s|-| |)acres?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (20,000 km²)$2'); txt.value=txt.value.replace(/([^y]\ssix(?:\s|-| |)million(?:\s|-| |)acres?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (24,000 km²)$2'); txt.value=txt.value.replace(/([^y]\sseven(?:\s|-| |)million(?:\s|-| |)acres?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (28,000 km²)$2'); txt.value=txt.value.replace(/([^y]\seight(?:\s|-| |)million(?:\s|-| |)acres?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (32,000 km²)$2'); txt.value=txt.value.replace(/([^y]\snine(?:\s|-| |)million(?:\s|-| |)acres?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (36,000 km²)$2'); txt.value=txt.value.replace(/([^y]\sten(?:\s|-| |)million(?:\s|-| |)acres?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (40,000 km²)$2');

//acre:plural txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]+\d\d[\d\.]*)(?:\s|-| |)(?:acres|\[\[acres\]\]|\[\[acre\]\]s)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1\{\{convert|$2|acre|km2\}\}$3'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d?\d\.\d+)(?:\s|-| |)(?:acres|\[\[acres\]\]|\[\[acre\]\]s)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1\{\{convert|$2|acre|m2\}\}$3'); //acre:singular txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]+\d\d[\d\.]*)(?:\s|-| |)(?:acre|\[\[acre\]\])([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1\{\{convert|$2|acre|km2|sing=on\}\}$3'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d?\d\.\d+)(?:\s|-| |)(?:acre|\[\[acre\]\])([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1\{\{convert|$2|acre|m2|sing=on\}\}$3');

//undo protection for acre feet txt.value=txt.value.replace(/xtempx(acre.feet)ytempy/gi, '$1');

// foot pound txt.value=txt.value.replace(/(\W)lbs?[\s-.·•\/]{1,2}ft([^²\w])/gi, '$1ft·lbf$2'); txt.value=txt.value.replace(/(\W)lbs?ft([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1ft·lbf$2'); txt.value=txt.value.replace(/ftlbs?([:;,\.?!]?\s[^\d\(\)\/\\])/gi, 'ft·lbf$1'); txt.value=txt.value.replace(/ft[\s-.·•\/]{1,2}lbs?([:;,\.?!]?\s[^\d\(\)\/\\])/gi, 'ft·lbf$1'); txt.value=txt.value.replace(/ftlbs?([:;,\.?!]?\s[^\d\(\)\/\\])/gi, 'ft·lbf$1'); txt.value=txt.value.replace(/ft[\s-.·•\/]{1,2}lbf([^\|])/gi, 'ft·lbf$1'); txt.value=txt.value.replace(/ft[\s-.·•\/]{1,2}lbff/gi, 'ft·lbf'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-| |)pounds?(?:\s|-| |)feet([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1\{\{convert|$2|ft.lbf|N.m\}\}$3'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-| |)foot(?:\s|-| |)pounds([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1\{\{convert|$2|ft.lbf|N.m\}\}$3'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-| |)pound(?:\s|-| |)foot([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1\{\{convert|$2|ft.lbf|N.m|sing=on\}\}$3'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-| |)foot(?:\s|-| |)pound([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1\{\{convert|$2|ft.lbf|N.m|sing=on\}\}$3'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-| |)ft.lbf([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1\{\{convert|$2|ft.lbf|N.m|abbr=on\}\}$3');

// pound force txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(\s|-| |)lbs?.?\s(thrust|of\sthrust|force|of\sforce)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1$2$3lbf $4$5'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*000)(?:\s|-| |)pounds\sforce([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|lbf|kN\}\}$3'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-| |)pounds\sforce([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|lbf|N\}\}$3'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*000)(?:\s|-| |)pound\sforce([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|lbf|kN|sing=on\}\}$3'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-| |)pound\sforce([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|lbf|N|sing=on\}\}$3'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*000)(?:\s|-| |)lbf([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|lbf|kN|abbr=on\}\}$3'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-| |)lbf([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|lbf|abbr=on\}\}$3');

// pound weight. Parsed after foot pound and pound force txt.value=txt.value.replace(/\[\[pound\s\(weight\)\|([^\]]+)\]\]/gi, '$1'); txt.value=txt.value.replace(/\|lbs?\.\]\]/gi, '|lb]]'); txt.value=txt.value.replace(/(\d)\s?lbs?([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 lb$2'); txt.value=txt.value.replace(/(\d\+?)\s?lbs?([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 lb$2'); txt.value=txt.value.replace(/(\d) lbs?([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 lb$2'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-| |)lb([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|lb|abbr=on\}\}$3'); //pounds and ounces - plural txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-| |)pounds(?:\s|-| |)(\d[\d,\.]*)(?:\s|-| |)ounces?([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|lb|$3|oz|kg\}\}$4'); //pounds and ounces - singular txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-| |)pound(?:\s|-| |)(\d[\d,\.]*)(?:\s|-| |)ounces?([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|lb|$3|oz|kg|sing=on\}\}$4'); //pounds and ounces - abbreviated txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-| |)lbs?\.?,?(?:\s|-| |)(\d[\d,\.]*)(?:\s|-| |)oz\.?([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|lb|$3|oz|kg|abbr=on\}\}$4');

//foot and inch: plural txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-| |)feet\.?(?:\s|-| |)(\d[\d,\.]*)(?:\s|-| |)(?:in|ins|inch|inches)\.?([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|ft|$3|in|m\}\}$4'); //foot and inch: singular txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-| |)foot\.?(?:\s|-| |)(\d[\d,\.]*)(?:\s|-| |)(?:in|ins|inch|inches)\.?([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|ft|$3|in|m|sing=on\}\}$4'); //foot and inch: abbreviated txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-| |)ft\.?(?:\s|-| |)(\d[\d,\.]*)(?:\s|-| |)(?:in|ins|inch|inches)\.?([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|ft|$3|in|m|abbr=on\}\}$4');

//foot (again). Parsed after 'foot per second' and 'foot pound' //foot: plural txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-| |)feet([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|ft|m\}\}$3'); //foot: singular txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-| |)foot([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|ft|m|sing=on\}\}$3'); //foot: abbreviated txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-| |)ft\.?([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|ft|m|abbr=on\}\}$3');

//inch: plural txt.value=txt.value.replace(/([^\Wt'’]\s)(\d[\d,\.]*)(?:\s|-| |)inches([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|in|mm\}\}$3'); // inch: plural with number in words txt.value=txt.value.replace(/([^ty]\sthree(?:\s|-| |)(?:inches|\[\[inches\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (76 mm) $2'); txt.value=txt.value.replace(/([^ty]\sfour(?:\s|-| |)(?:inches|\[\[inches\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (102 mm) $2'); txt.value=txt.value.replace(/([^ty]\sfive(?:\s|-| |)(?:inches|\[\[inches\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (127 mm) $2'); txt.value=txt.value.replace(/([^ty]\ssix(?:\s|-| |)(?:inches|\[\[inches\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (152 mm) $2'); txt.value=txt.value.replace(/([^ty]\sseven(?:\s|-| |)(?:inches|\[\[inches\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (178 mm) $2'); txt.value=txt.value.replace(/([^ty]\seight(?:\s|-| |)(?:inches|\[\[inches\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (203 mm) $2'); txt.value=txt.value.replace(/([^ty]\snine(?:\s|-| |)(?:inches|\[\[inches\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (229 mm) $2'); txt.value=txt.value.replace(/([^ty]\sten(?:\s|-| |)(?:inches|\[\[inches\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (254 mm) $2'); txt.value=txt.value.replace(/([^ty]\seleven(?:\s|-| |)(?:inches|\[\[inches\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (279 mm) $2'); txt.value=txt.value.replace(/([^ty]\stwelve(?:\s|-| |)(?:inches|\[\[inches\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (305 mm) $2'); txt.value=txt.value.replace(/([^ty]\sthirteen(?:\s|-| |)(?:inches|\[\[inches\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (330 mm) $2'); txt.value=txt.value.replace(/([^ty]\sfourteen(?:\s|-| |)(?:inches|\[\[inches\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (356 mm) $2'); txt.value=txt.value.replace(/([^ty]\sfifteen(?:\s|-| |)(?:inches|\[\[inches\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (381 mm) $2'); txt.value=txt.value.replace(/([^ty]\ssixteen(?:\s|-| |)(?:inches|\[\[inches\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (406 mm) $2'); //inch: singular txt.value=txt.value.replace(/([^\Wt'’]\s)(\d[\d,\.]*)(?:\s|-| |)(?:inch|\[\[inch\]\])([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|in|mm|sing=on\}\}$3'); txt.value=txt.value.replace(/({convert\|\d+\|(?:in|mm|cm)[^\}]*)\|lk=(?:on|in|out)/g, '$1'); // inch: singular with number in words txt.value=txt.value.replace(/([^ty]\sthree(?:\s|-| |)(?:inch|\[\[inch\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (76 mm) $2'); txt.value=txt.value.replace(/([^ty]\sfour(?:\s|-| |)(?:inch|\[\[inch\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (102 mm) $2'); txt.value=txt.value.replace(/([^ty]\sfive(?:\s|-| |)(?:inch|\[\[inch\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (127 mm) $2'); txt.value=txt.value.replace(/([^ty]\ssix(?:\s|-| |)(?:inch|\[\[inch\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (152 mm) $2'); txt.value=txt.value.replace(/([^ty]\sseven(?:\s|-| |)(?:inch|\[\[inch\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (178 mm) $2'); txt.value=txt.value.replace(/([^ty]\seight(?:\s|-| |)(?:inch|\[\[inch\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (203 mm) $2'); txt.value=txt.value.replace(/([^ty]\snine(?:\s|-| |)(?:inch|\[\[inch\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (229 mm) $2'); txt.value=txt.value.replace(/([^ty]\sten(?:\s|-| |)(?:inch|\[\[inch\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (254 mm) $2'); txt.value=txt.value.replace(/([^ty]\seleven(?:\s|-| |)(?:inch|\[\[inch\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (279 mm) $2'); txt.value=txt.value.replace(/([^ty]\stwelve(?:\s|-| |)(?:inch|\[\[inch\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (305 mm) $2'); txt.value=txt.value.replace(/([^ty]\sthirteen(?:\s|-| |)(?:inch|\[\[inch\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (330 mm) $2'); txt.value=txt.value.replace(/([^ty]\sfourteen(?:\s|-| |)(?:inch|\[\[inch\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (356 mm) $2'); txt.value=txt.value.replace(/([^ty]\sfifteen(?:\s|-| |)(?:inch|\[\[inch\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (381 mm) $2'); txt.value=txt.value.replace(/([^ty]\ssixteen(?:\s|-| |)(?:inch|\[\[inch\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (406 mm) $2');

// horsepower txt.value=txt.value.replace(/\.28\s?(bhp|ihp|shp)\.29\|/gi, '($1)|'); txt.value=txt.value.replace(/(\d)(?:\s|-|)(horsepower|hp|bhp|ihp|shp)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 $2$3'); txt.value=txt.value.replace(/(\d) (horsepower|hp|bhp|ihp|shp)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 $2$3'); txt.value=txt.value.replace(/(\d)(?:\s|-|)horse(?:\s|-|)power([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 horsepower$2'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-| |)(?:horsepower|\[\[horsepower\]\])([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|hp\}\}$3'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-| |)(indicated(?:\s|-| |)horsepower)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|ihp\}\}$4'); txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-| |)(hp|bhp|ihp|shp)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|$3|abbr=on\}\}$4');

txt.value=txt.value.replace(/({convert\|\d+\|)horsepower\|/gi, '$1horsepower|'); txt.value=txt.value.replace(/({convert\|\d+\|)hp\|/gi, '$1hp|'); txt.value=txt.value.replace(/({convert\|\d+\|)bhp\|/gi, '$1bhp|'); txt.value=txt.value.replace(/({convert\|\d+\|)ihp\|/gi, '$1ihp|'); txt.value=txt.value.replace(/({convert\|\d+\|)shp\|/gi, '$1shp|');

// rpm txt.value=txt.value.replace(/(\d)\s?rpm([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 rpm$2'); txt.value=txt.value.replace(/(\d) rpm([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 rpm$2'); txt.value=txt.value.replace(/(\d)\-rpm([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 rpm$2');

// decibel txt.value=txt.value.replace(/(\d)\s?(dB)\b/g, '$1 $2');

// bits per second txt.value=txt.value.replace(/(\d)\s?([KkMmGgTt])?(?:bps|bits\/s|b\/s)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1 $2bit/s$3'); //txt.value=txt.value.replace(/(\d)\s?bps([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 bit/s$2'); txt.value=txt.value.replace(/(\d) ([KkMmGgTt])?(?:bps|bits\/s|b\/s)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1 $2bit/s$3'); //txt.value=txt.value.replace(/(\d) bps([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 bit/s$2'); txt.value=txt.value.replace(/bits?\/sec([:;,\.?!]?\s[^\d\(\)\/\\])/gi, 'bit/s$1');

// bytes per second txt.value=txt.value.replace(/([KkMmGgTt])(?:Bps|bytes?\/s)([:;,\.?!]?\s[^\d\(\)\/\\])/g, ' $1byte/s$2'); txt.value=txt.value.replace(/bytes?\/s([:;,\.?!]?\s[^\d\(\)\/\\])/gi, 'byte/s$1');

// capitalization of prefix with bits and bytes txt.value=txt.value.replace(/K(bit|B|byte)\/s/g, 'k$1/s'); txt.value=txt.value.replace(/m(bit|B|byte)\/s/g, 'M$1/s'); txt.value=txt.value.replace(/g(bit|B|byte)\/s/g, 'G$1/s'); txt.value=txt.value.replace(/t(bit|B|byte)\/s/g, 'T$1/s');

// space with bits and bytes txt.value=txt.value.replace(/([^\w]\d)\s?(k|M|G|T)(bit|B)/g, '$1 $2$3');

//aviation specifications: unprotect 'main=' and 'alt=' txt.value=txt.value.replace(/((?:main|alt)\s?=\s?)xx(\d)/gi, '$1$2');

//change format of convert template variables txt.value=txt.value.replace(/({convert\|[^}]+km):h/g, '$1/h'); txt.value=txt.value.replace(/({convert\|[^}]+mi):h/g, '$1/h'); txt.value=txt.value.replace(/({convert\|[^}]+ft):s/g, '$1/s'); txt.value=txt.value.replace(/({convert\|[^}]+m):s/g, '$1/s');

//change deprecated knot in template code txt.value=txt.value.replace(/(\{\{convert\|[^}]*knot)\|km\/h mph([^}]*\}\})/gi, '$1$2');

txt.value=txt.value.replace(/\{\{convert\|(1.5)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (2.8 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(7)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (13 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(10)\|knot\|km\/h(?:\|\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (19 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(10)\|knot\|km\/h(?:\|-1|)(?:\|lk=on|)\}\}/gi, '$1 knots (20 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(11)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (20 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(12)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (22 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(13)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (24 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(14)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (26 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(15)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (28 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(16)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (30 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(17)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (31 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(18)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (33 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(19)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (35 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(19\.1)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (35.4 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(20)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (37 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(21)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (39 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(20\.8)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (38.5 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(21\.06)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (39.00 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(23)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (43 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(23\.4)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (43.3 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(25)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (46 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(27\.5)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (50.9 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(28)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (52 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(29\.98)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (55.52 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(30)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (56 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(31)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (57 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(35\.5)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (65.7 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(39)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (72 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(40)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (74 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(50)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (93 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(60)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (110 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(70)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (130 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(80)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (150 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(90)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (170 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(100)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (190 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(110)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (200 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(120)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (220 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(130)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (240 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(140)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (260 km/h)');

txt.value=txt.value.replace(/\{\{convert\|(9\.0)\|knot(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (17 km/h/10 mph)'); txt.value=txt.value.replace(/\{\{convert\|(10)\|knot(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (19 km/h/12 mph)'); txt.value=txt.value.replace(/\{\{convert\|(11)\|knot(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (20 km/h/13 mph)'); txt.value=txt.value.replace(/\{\{convert\|(12)\|knot(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (22 km/h/14 mph)'); txt.value=txt.value.replace(/\{\{convert\|(13)\|knot(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (24 km/h/15 mph)'); txt.value=txt.value.replace(/\{\{convert\|(14)\|knot(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (26 km/h/16 mph)'); txt.value=txt.value.replace(/\{\{convert\|(14\.1)\|knot(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (26.1 km/h/16.2 mph)'); txt.value=txt.value.replace(/\{\{convert\|(15)\|knot(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (28 km/h/17 mph)'); txt.value=txt.value.replace(/\{\{convert\|(16)\|knot(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (30 km/h/18 mph)'); txt.value=txt.value.replace(/\{\{convert\|(17)\|knot(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (31 km/h/20 mph)'); txt.value=txt.value.replace(/\{\{convert\|(18)\|knot(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (33 km/h/21 mph)'); txt.value=txt.value.replace(/\{\{convert\|(19)\|knot(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (35 km/h/22 mph)'); txt.value=txt.value.replace(/\{\{convert\|(20)\|knot(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (37 km/h/23 mph)'); txt.value=txt.value.replace(/\{\{convert\|(21\.5)\|knot(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (39.8 km/h/24.7 mph)'); txt.value=txt.value.replace(/\{\{convert\|(23)\|knot(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (43 km/h/26 mph)'); txt.value=txt.value.replace(/\{\{convert\|(24)\|knot(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (44 km/h/28 mph)'); txt.value=txt.value.replace(/\{\{convert\|(33\.8)\|knot(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (62.6 km/h/38.9 mph)'); txt.value=txt.value.replace(/\{\{convert\|(39)\|knot(?:\|-?\d|)(?:\|lk=on|)\}\}/gi, '$1 knots (72 km/h/45 mph)');

txt.value=txt.value.replace(/\{\{convert\|(24)\|km\/h\|knot(?:\|\d|)(?:\|lk=on|)\}\}/gi, '$1 km/h (13 kn)');

txt.value=txt.value.replace(/\{\{convert\|(10)\|knot\|km\/h(?:\|\d|)(?:\|lk=on|)\|sing=on(?:\|lk=on|)\}\}/gi, '$1 knot (19 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(10)\|knot\|km\/h(?:\|-1\d|)(?:\|lk=on|)\|sing=on(?:\|lk=on|)\}\}/gi, '$1 knot (20 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(11)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\|sing=on(?:\|lk=on|)\}\}/gi, '$1 knot (20 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(12)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\|sing=on(?:\|lk=on|)\}\}/gi, '$1 knot (22 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(13)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\|sing=on(?:\|lk=on|)\}\}/gi, '$1 knot (24 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(14)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\|sing=on(?:\|lk=on|)\}\}/gi, '$1 knot (26 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(15)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\|sing=on(?:\|lk=on|)\}\}/gi, '$1 knot (28 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(16)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\|sing=on(?:\|lk=on|)\}\}/gi, '$1 knot (30 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(17)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\|sing=on(?:\|lk=on|)\}\}/gi, '$1 knot (31 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(18)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\|sing=on(?:\|lk=on|)\}\}/gi, '$1 knot (33 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(19)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\|sing=on(?:\|lk=on|)\}\}/gi, '$1 knot (35 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(19\.1)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\|sing=on(?:\|lk=on|)\}\}/gi, '$1 knot (35.4 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(19\.5)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\|sing=on(?:\|lk=on|)\}\}/gi, '$1 knot (36.1 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(20)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\|sing=on(?:\|lk=on|)\}\}/gi, '$1 knot (37 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(23)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\|sing=on(?:\|lk=on|)\}\}/gi, '$1 knot (43 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(27\.5)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\|sing=on(?:\|lk=on|)\}\}/gi, '$1 knot (50.9 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(28)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\|sing=on(?:\|lk=on|)\}\}/gi, '$1 knot (52 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(30)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\|sing=on(?:\|lk=on|)\}\}/gi, '$1 knot (56 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(39)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\|sing=on(?:\|lk=on|)\}\}/gi, '$1 knot (72 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(40)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\|sing=on(?:\|lk=on|)\}\}/gi, '$1 knot (74 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(50)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\|sing=on(?:\|lk=on|)\}\}/gi, '$1 knot (93 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(60)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\|sing=on(?:\|lk=on|)\}\}/gi, '$1 knot (110 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(70)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\|sing=on(?:\|lk=on|)\}\}/gi, '$1 knot (130 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(80)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\|sing=on(?:\|lk=on|)\}\}/gi, '$1 knot (150 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(90)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\|sing=on(?:\|lk=on|)\}\}/gi, '$1 knot (170 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(100)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\|sing=on(?:\|lk=on|)\}\}/gi, '$1 knot (190 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(110)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\|sing=on(?:\|lk=on|)\}\}/gi, '$1 knot (200 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(120)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\|sing=on(?:\|lk=on|)\}\}/gi, '$1 knot (220 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(130)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\|sing=on(?:\|lk=on|)\}\}/gi, '$1 knot (240 km/h)'); txt.value=txt.value.replace(/\{\{convert\|(140)\|knot\|km\/h(?:\|-?\d|)(?:\|lk=on|)\|sing=on(?:\|lk=on|)\}\}/gi, '$1 knot (260 km/h)');

txt.value=txt.value.replace(/\{\{convert\|(9\.0)\|knot(?:\|-?\d|)(?:\|lk=on|)\|sing=on(?:\|lk=on|)\}\}/gi, '$1 knot (17 km/h/10 mph)'); txt.value=txt.value.replace(/\{\{convert\|(10)\|knot(?:\|-?\d|)(?:\|lk=on|)\|sing=on(?:\|lk=on|)\}\}/gi, '$1 knot (19 km/h/12 mph)'); txt.value=txt.value.replace(/\{\{convert\|(11)\|knot(?:\|-?\d|)(?:\|lk=on|)\|sing=on(?:\|lk=on|)\}\}/gi, '$1 knot (20 km/h/13 mph)'); txt.value=txt.value.replace(/\{\{convert\|(12)\|knot(?:\|-?\d|)(?:\|lk=on|)\|sing=on(?:\|lk=on|)\}\}/gi, '$1 knot (22 km/h/14 mph)'); txt.value=txt.value.replace(/\{\{convert\|(13)\|knot(?:\|-?\d|)(?:\|lk=on|)\|sing=on(?:\|lk=on|)\}\}/gi, '$1 knot (24 km/h/15 mph)'); txt.value=txt.value.replace(/\{\{convert\|(14)\|knot(?:\|-?\d|)(?:\|lk=on|)\|sing=on(?:\|lk=on|)\}\}/gi, '$1 knot (26 km/h/16 mph)'); txt.value=txt.value.replace(/\{\{convert\|(15)\|knot(?:\|-?\d|)(?:\|lk=on|)\|sing=on(?:\|lk=on|)\}\}/gi, '$1 knot (28 km/h/17 mph)'); txt.value=txt.value.replace(/\{\{convert\|(16)\|knot(?:\|-?\d|)(?:\|lk=on|)\|sing=on(?:\|lk=on|)\}\}/gi, '$1 knot (30 km/h/18 mph)'); txt.value=txt.value.replace(/\{\{convert\|(17)\|knot(?:\|-?\d|)(?:\|lk=on|)\|sing=on(?:\|lk=on|)\}\}/gi, '$1 knot (31 km/h/20 mph)'); txt.value=txt.value.replace(/\{\{convert\|(18)\|knot(?:\|-?\d|)(?:\|lk=on|)\|sing=on(?:\|lk=on|)\}\}/gi, '$1 knot (33 km/h/21 mph)'); txt.value=txt.value.replace(/\{\{convert\|(19)\|knot(?:\|-?\d|)(?:\|lk=on|)\|sing=on(?:\|lk=on|)\}\}/gi, '$1 knot (35 km/h/22 mph)'); txt.value=txt.value.replace(/\{\{convert\|(20)\|knot(?:\|-?\d|)(?:\|lk=on|)\|sing=on(?:\|lk=on|)\}\}/gi, '$1 knot (37 km/h/23 mph)'); txt.value=txt.value.replace(/\{\{convert\|(23)\|knot(?:\|-?\d|)(?:\|lk=on|)\|sing=on(?:\|lk=on|)\}\}/gi, '$1 knot (43 km/h/26 mph)'); txt.value=txt.value.replace(/\{\{convert\|(24)\|knot(?:\|-?\d|)(?:\|lk=on|)\|sing=on(?:\|lk=on|)\}\}/gi, '$1 knot (44 km/h/28 mph)'); txt.value=txt.value.replace(/\{\{convert\|(39)\|knot(?:\|-?\d|)(?:\|lk=on|)\|sing=on(?:\|lk=on|)\}\}/gi, '$1 knot (72 km/h/45 mph)');

txt.value=txt.value.replace(/({convert\|[^}]+\|kn)ot(\||})/g, '$1$2'); txt.value=txt.value.replace(/(\{\{convert\|[^}]*kn)ot([^}]*abbr=on\}\})/gi, '$1$2');

//replace other templates with convert template txt.value=txt.value.replace(/\{\{mi\sto\skm\|(\d{1,9})\}\}/gi, '\{\{convert|$1|mi|km\}\}'); txt.value=txt.value.replace(/\{\{mi\sto\skm\|(\d{1,9})\|round[^\}]{1,5\}\}}/gi, '\{\{convert|$1|mi|km\}\}'); txt.value=txt.value.replace(/\{\{mi2\sto\skm2\|(\d{1,9})\}\}/gi, '\{\{convert|$1|mi|km\}\}'); txt.value=txt.value.replace(/\{\{mi2\sto\skm2\|(\d{1,9})\|round[^\}]{1,5\}\}}/gi, '\{\{convert|$1|mi|km\}\}');

//replace rail gauge template txt.value=txt.value.replace(/\{\{(\d?\d)\s?in\}\}/gi, '\{\{convert|$1|in|mm|0|abbr=on\}\}'); txt.value=txt.value.replace(/\{\{(\d?\d)\s?ft\}\}/gi, '\{\{convert|$1|ft|mm|0|abbr=on\}\}'); txt.value=txt.value.replace(/\{\{(\d?\d)\s?ft\s?(\d?\d)\s?in\}\}/gi, '\{\{convert|$1|ft|$2|in|mm|0|abbr=on\}\}'); txt.value=txt.value.replace(/\{\{(\d?\d)\s?ft\s?(\d?\d\.\d+)\s?in\}\}/gi, '\{\{convert|$1|ft|$2|in|mm|0|abbr=on\}\}');

txt.value=txt.value.replace(/(\{\{railgauge\|[^}]+)\|lk=on(\}\})/gi, '$1$2'); txt.value=txt.value.replace(/\{\{railgauge\|(\d?\d)\s?in\}\}/gi, '\{\{convert|$1|in|mm|0|abbr=on\}\}'); txt.value=txt.value.replace(/\{\{railgauge\|(\d?\d)\s?ft\}\}/gi, '\{\{convert|$1|ft|mm|0|abbr=on\}\}'); txt.value=txt.value.replace(/\{\{railgauge\|(\d?\d)\s?ft\s?(\d?\d)\s?in\}\}/gi, '\{\{convert|$1|ft|$2|in|mm|0|abbr=on\}\}'); txt.value=txt.value.replace(/\{\{railgauge\|(\d?\d)\s?ft\s?(\d?\d\.\d+)\s?in\}\}/gi, '\{\{convert|$1|ft|$2|in|mm|0|abbr=on\}\}');

txt.value=txt.value.replace(/\{\{railgauge\|24\}\}/gi, '\{\{convert|2|ft|mm|0|abbr=on\}\}'); txt.value=txt.value.replace(/\{\{railgauge\|25\}\}/gi, '\{\{convert|2|ft|1|in|mm|0|abbr=on\}\}'); txt.value=txt.value.replace(/\{\{railgauge\|26\}\}/gi, '\{\{convert|2|ft|2|in|mm|0|abbr=on\}\}'); txt.value=txt.value.replace(/\{\{railgauge\|27\}\}/gi, '\{\{convert|2|ft|3|in|mm|0|abbr=on\}\}'); txt.value=txt.value.replace(/\{\{railgauge\|28\}\}/gi, '\{\{convert|2|ft|4|in|mm|0|abbr=on\}\}'); txt.value=txt.value.replace(/\{\{railgauge\|29\}\}/gi, '\{\{convert|2|ft|5|in|mm|0|abbr=on\}\}'); txt.value=txt.value.replace(/\{\{railgauge\|30\}\}/gi, '\{\{convert|2|ft|6|in|mm|0|abbr=on\}\}'); txt.value=txt.value.replace(/\{\{railgauge\|31\}\}/gi, '\{\{convert|2|ft|7|in|mm|0|abbr=on\}\}'); txt.value=txt.value.replace(/\{\{railgauge\|32\}\}/gi, '\{\{convert|2|ft|8|in|mm|0|abbr=on\}\}'); txt.value=txt.value.replace(/\{\{railgauge\|33\}\}/gi, '\{\{convert|2|ft|9|in|mm|0|abbr=on\}\}'); txt.value=txt.value.replace(/\{\{railgauge\|34\}\}/gi, '\{\{convert|2|ft|10|in|mm|0|abbr=on\}\}'); txt.value=txt.value.replace(/\{\{railgauge\|35\}\}/gi, '\{\{convert|2|ft|11|in|mm|0|abbr=on\}\}'); txt.value=txt.value.replace(/\{\{railgauge\|36\}\}/gi, '\{\{convert|3|ft|mm|0|abbr=on\}\}'); txt.value=txt.value.replace(/\{\{railgauge\|37\}\}/gi, '\{\{convert|3|ft|1|in|mm|0|abbr=on\}\}'); txt.value=txt.value.replace(/\{\{railgauge\|38\}\}/gi, '\{\{convert|3|ft|2|in|mm|0|abbr=on\}\}'); txt.value=txt.value.replace(/\{\{railgauge\|39\}\}/gi, '\{\{convert|3|ft|3|in|mm|0|abbr=on\}\}'); txt.value=txt.value.replace(/\{\{railgauge\|40\}\}/gi, '\{\{convert|3|ft|4|in|mm|0|abbr=on\}\}'); txt.value=txt.value.replace(/\{\{railgauge\|41\}\}/gi, '\{\{convert|3|ft|5|in|mm|0|abbr=on\}\}'); txt.value=txt.value.replace(/\{\{railgauge\|42\}\}/gi, '\{\{convert|3|ft|6|in|mm|0|abbr=on\}\}'); txt.value=txt.value.replace(/\{\{railgauge\|48\}\}/gi, '\{\{convert|4|ft|mm|0|abbr=on\}\}'); txt.value=txt.value.replace(/\{\{railgauge\|49\}\}/gi, '\{\{convert|4|ft|1|in|mm|0|abbr=on\}\}'); txt.value=txt.value.replace(/\{\{railgauge\|50\}\}/gi, '\{\{convert|4|ft|2|in|mm|0|abbr=on\}\}'); txt.value=txt.value.replace(/\{\{railgauge\|51\}\}/gi, '\{\{convert|4|ft|3|in|mm|0|abbr=on\}\}'); txt.value=txt.value.replace(/\{\{railgauge\|52\}\}/gi, '\{\{convert|4|ft|4|in|mm|0|abbr=on\}\}'); txt.value=txt.value.replace(/\{\{railgauge\|53\}\}/gi, '\{\{convert|4|ft|5|in|mm|0|abbr=on\}\}'); txt.value=txt.value.replace(/\{\{railgauge\|54\}\}/gi, '\{\{convert|4|ft|6|in|mm|0|abbr=on\}\}'); txt.value=txt.value.replace(/\{\{railgauge\|55\}\}/gi, '\{\{convert|4|ft|7|in|mm|0|abbr=on\}\}'); txt.value=txt.value.replace(/\{\{railgauge\|56\}\}/gi, '\{\{convert|4|ft|8|in|mm|0|abbr=on\}\}'); txt.value=txt.value.replace(/\{\{railgauge\|57\}\}/gi, '\{\{convert|4|ft|9|in|mm|0|abbr=on\}\}'); txt.value=txt.value.replace(/\{\{railgauge\|58\}\}/gi, '\{\{convert|4|ft|10|in|mm|0|abbr=on\}\}'); txt.value=txt.value.replace(/\{\{railgauge\|59\}\}/gi, '\{\{convert|4|ft|11|in|mm|0|abbr=on\}\}'); txt.value=txt.value.replace(/\{\{railgauge\|60\}\}/gi, '\{\{convert|5|ft|mm|0|abbr=on\}\}'); txt.value=txt.value.replace(/\{\{railgauge\|61\}\}/gi, '\{\{convert|5|ft|1|in|mm|0|abbr=on\}\}'); txt.value=txt.value.replace(/\{\{railgauge\|62\}\}/gi, '\{\{convert|5|ft|2|in|mm|0|abbr=on\}\}'); txt.value=txt.value.replace(/\{\{railgauge\|63\}\}/gi, '\{\{convert|5|ft|3|in|mm|0|abbr=on\}\}'); txt.value=txt.value.replace(/\{\{railgauge\|64\}\}/gi, '\{\{convert|5|ft|4|in|mm|0|abbr=on\}\}'); txt.value=txt.value.replace(/\{\{railgauge\|65\}\}/gi, '\{\{convert|5|ft|5|in|mm|0|abbr=on\}\}'); txt.value=txt.value.replace(/\{\{railgauge\|66\}\}/gi, '\{\{convert|5|ft|6|in|mm|0|abbr=on\}\}'); txt.value=txt.value.replace(/\{\{railgauge\|67\}\}/gi, '\{\{convert|5|ft|7|in|mm|0|abbr=on\}\}'); txt.value=txt.value.replace(/\{\{railgauge\|68\}\}/gi, '\{\{convert|5|ft|8|in|mm|0|abbr=on\}\}'); txt.value=txt.value.replace(/\{\{railgauge\|69\}\}/gi, '\{\{convert|5|ft|9|in|mm|0|abbr=on\}\}'); txt.value=txt.value.replace(/\{\{railgauge\|70\}\}/gi, '\{\{convert|5|ft|10|in|mm|0|abbr=on\}\}'); txt.value=txt.value.replace(/\{\{railgauge\|71\}\}/gi, '\{\{convert|5|ft|11|in|mm|0|abbr=on\}\}'); txt.value=txt.value.replace(/\{\{railgauge\|72\}\}/gi, '\{\{convert|6|ft|mm|0|abbr=on\}\}');

//remove commas from numerical values in convert template txt.value=txt.value.replace(/({convert\|\d+),(\d)/g, '$1$2'); txt.value=txt.value.replace(/({convert\|\d+),(\d)/g, '$1$2'); txt.value=txt.value.replace(/({convert\|\d+),(\d)/g, '$1$2'); txt.value=txt.value.replace(/({convert\|\d+),(\d)/g, '$1$2'); txt.value=txt.value.replace(/({convert\|\d+),(\d)/g, '$1$2');

//remove leading zeros from convert template txt.value=txt.value.replace(/({convert\|)0(\d)/g, '$1$2'); txt.value=txt.value.replace(/({convert\|)0(\d)/g, '$1$2'); txt.value=txt.value.replace(/({convert\|)0(\d)/g, '$1$2');

//Remove surprise or 'Easter egg' diversions linking unit name to orders of magnitude articles txt.value=txt.value.replace(/\[\[1\s?_?E\s?[\-\+]?\d{1,2}\s?..?\|([^\]]{1,50})\]\]/gi, '$1'); txt.value=txt.value.replace(/\[\[Orders\sof\smagnitude\s\([^\)]+\)\|([^\]]{1,50})\]\]/gi, '$1');

}

function all_dates { var txt = document.editform.wpTextbox1; part_dates;

//Remove full US format dates, ensure that comma is present txt.value=txt.value.replace(/\[\[((?:January|February|March|April|May|June|July|August|September|October|November|December)\s\d\d?)\]\],?\s?\s?\[\[(\d{1,4})\]\]/gi,'$1, $2');

//Remove month+day and day+month formats txt.value=txt.value.replace(/\[\[(\d\d?\s(?:January|February|March|April|May|June|July|August|September|October|November|December))\]\]/gi,'$1'); txt.value=txt.value.replace(/\[\[(\d\d?\s(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec))\]\]/g,'$1'); txt.value=txt.value.replace(/\[\[((?:January|February|March|April|May|June|July|August|September|October|November|December)\s\d\d?)\]\]/gi,'$1'); txt.value=txt.value.replace(/\[\[((?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s\d\d?)\]\]/g,'$1');

//year: temporary change to protect split linked ISO dates. Undone below txt.value=txt.value.replace(/(\[\[\d{1,4}\]\]-\[\[\d\d-\d\d\]\])/gi, 'qq$1'); //year: now remove unprotected linked years txt.value=txt.value.replace(/([^q])\[\[(\d{1,4})\]\]/gi, '$1$2'); //year: Undo temporary change to protect part linked ISO dates txt.value=txt.value.replace(/qq(\[\[)/gi, '$1');

}

function run_part_dates { var txt = document.editform.wpTextbox1; part_dates;

var txt = document.editform.wpSummary; var summary = "Script-assisted. Units/dates/other"; if (txt.value.indexOf(summary) == -1) { if (txt.value.match(/[^\*\/\s][^\/\s]?\s*$/)) { txt.value += " | "; }		txt.value += summary; }   document.editform.wpDiff.click } $(function {    if(document.forms.editform) { //        mw.util.addPortletLink('p-cactions', 'javascript:run_part_dates', 'part dates', 'ca-unitfixer', 'Fixes some unit formatting', , );    } });

function run_all_dates { var txt = document.editform.wpTextbox1; all_dates; // Add a tag to the summary box var txt = document.editform.wpSummary; var summary = "Script-assisted. Units/dates/other"; if (txt.value.indexOf(summary) == -1) { if (txt.value.match(/[^\*\/\s][^\/\s]?\s*$/)) { txt.value += " | "; }		txt.value += summary; } // Press the diff button to check it   document.editform.wpDiff.click } $(function {    if(document.forms.editform) { //        mw.util.addPortletLink('p-cactions', 'javascript:run_all_dates', 'all dates', 'ca-unitfixer', 'Fixes some unit formatting', , );    } });

function run_year_in_blah { var txt = document.editform.wpTextbox1; year_in_blah;

// Add a tag to the summary box var txt = document.editform.wpSummary; var summary = "Script-assisted. Units/dates/other"; if (txt.value.indexOf(summary) == -1) { if (txt.value.match(/[^\*\/\s][^\/\s]?\s*$/)) { txt.value += " | "; }		txt.value += summary; }

// Press the diff button to check it   document.editform.wpDiff.click } $(function {    if(document.forms.editform) { //        mw.util.addPortletLink('p-cactions', 'javascript:run_year_in_blah', 'year in blah', 'ca-unitfixer', 'Fixes some unit formatting', , );    } });

function run_formatgeneral { var txt = document.editform.wpTextbox1; formatgeneral;

// Add a tag to the summary box var txt = document.editform.wpSummary; var summary = "Script-assisted. Units/dates/other"; if (txt.value.indexOf(summary) == -1) { if (txt.value.match(/[^\*\/\s][^\/\s]?\s*$/)) { txt.value += " | "; }		txt.value += summary; }

// Press the diff button to check it   document.editform.wpDiff.click } $(function {    if(document.forms.editform) { //        mw.util.addPortletLink('p-cactions', 'javascript:run_formatgeneral', 'units', 'ca-unitfixer', 'Fixes some unit formatting', , );    } });

function combined { var txt = document.editform.wpTextbox1; formatgeneral; part_dates;

// Add a tag to the summary box var txt = document.editform.wpSummary; var summary = "Script-assisted. Units/dates/other"; if (txt.value.indexOf(summary) == -1) { if (txt.value.match(/[^\*\/\s][^\/\s]?\s*$/)) { txt.value += " | "; }		txt.value += summary; }

// Press the diff button to check it   document.editform.wpDiff.click }

$(function {    if(document.forms.editform) { //        mw.util.addPortletLink('p-cactions', 'javascript:combined', 'dates+units', 'ca-unitfixer', 'Fixes some unit formatting', , ); //        mw.util.addPortletLink('p-cactions', , 'Note to users: script commands now in toolbox at bottom left beneath: What links here', 'ca-unitfixer', 'Fixes some unit formatting', , ); //        mw.util.addPortletLink('p-cactions', , 'B', 'ca-unitfixer', 'Fixes some unit formatting', , );    } });

// function LMmosdate { var txt = document.editform.wpTextbox1; txt.value = txt.value

//MOSDATE remove th in dates followed by -th, others //.replace(/([^\[])(January|February|March|April|May|June|July|August|September|October|November|December)\s(\d\d?)(th|st|nd|rd)/gi, '$1$2 $3') .replace(/(January|February|March|April|May|June|July|August|September|October|November|December)\s(\d\d?)(th|st|nd|rd)/gi, '$1 $2') .replace(/\[\[(January|February|March|April|May|June|July|August|September|October|November|December)\s(\d\d?)\]\]?(th|st|nd|rd)(<\/sup>)?/gi, '$1 $2') .replace(/(\D\d\d?)?(th|st|nd|rd)(<\/sup>)?\s(January|February|March|April|May|June|July|August|September|October|November|December)/gi, '$1 $5') .replace(/\s(\d{3}0)'s(\W)/gi, ' $1s$2'); }

function LMyearinX { var monthyear = new RegExp("\\[\\[(January|February|March|April|May|June|July|August|September|October|November|December),? *([0-9][0-9][0-9][0-9])\\]\\]", "g"); var txt = document.editform.wpTextbox1; txt.value = txt.value.replace(/\[\([1-2][0-9][0-9][0-9])\]\]/g, "[[$1");  txt.value = txt.value.replace(/([^,\]] |[^,\] ])\[\[([1-2][0-9][0-9][0-9])\]\]/g, "$1$2"); txt.value = txt.value.replace(monthyear, "$1 $2"); }

function protect_dates{ var txt = document.editform.wpTextbox1; //protect certain dates txt.value=txt.value.replace(/(september) (11[^\d])/gi, '$1xx$2'); txt.value=txt.value.replace(/(\[\[september)xx(11\]\])/gi, '$1 $2'); txt.value=txt.value.replace(/([^\d]7) (july)/gi, '$1xx$2'); txt.value=txt.value.replace(/(\[\[7)xx(july\]\])/gi, '$1 $2'); }

function unprotect_dates{ var txt = document.editform.wpTextbox1;

//unprotect certain dates txt.value=txt.value.replace(/(september)xx(11)/gi, '$1 $2'); txt.value=txt.value.replace(/(7)xx(july)/gi, '$1 $2'); }

function LMdayMonth(option) {

var daymonth = new RegExp("\\[\\[0?([1-3][0-9]|[0-9])(?:st|nd|rd|th|) (January|February|March|April|May|June|July|August|September|October|November|December)\\]\\],? *\\[\\[([0-9][0-9][0-9][0-9])\\]\\]", "g"); var monthday = new RegExp("\\[\\[(January|February|March|April|May|June|July|August|September|October|November|December) 0?([1-3][0-9]|[0-9])(?:st|nd|rd|th|)\\]\\](?:st|nd|rd|th|),? *\\[\\[([0-9][0-9][0-9][0-9])\\]\\]", "g"); var daymonth2 = new RegExp("\\[\\[0?([1-3][0-9]|[0-9])(?:st|nd|rd|th|) (January|February|March|April|May|June|July|August|September|October|November|December)\\]\\]", "g"); var monthday2 = new RegExp("\\[\\[(January|February|March|April|May|June|July|August|September|October|November|December) 0?([1-3][0-9]|[0-9])(?:st|nd|rd|th|)\\]\\](?:st|nd|rd|th|)", "g"); var txt = document.editform.wpTextbox1;

//fix 'bda' template redirect txt.value=txt.value.replace(/\{\{bda\|([^}]+)\}\}/gi, '\{\{birth date and age|$1\}\}');

if (option == 1) {

//change to dmy // dd Month txt.value = txt.value.replace(monthday, "$2 $1 $3"); txt.value = txt.value.replace(daymonth, "$1 $2 $3"); txt.value = txt.value.replace(monthday2, "$2 $1"); txt.value = txt.value.replace(daymonth2, "$1 $2");

//change deprecated dts2 template txt.value=txt.value.replace(/\{\{dts2\|(.*?)\|(.*?)\|(.*?)\}\}/gi, '\{\{dts|link=off|format=dmy|$3|$2|$1\}\}'); //fix dts template txt.value=txt.value.replace(/(\{\{dts\|)/gi, '$1link=off|format=dmy|'); txt.value=txt.value.replace(/(\{\{dts\|)link=off\|([^}]*link=off)/gi, '$1$2'); txt.value=txt.value.replace(/(\{\{dts\|)format=dmy\|([^}]*format=dmy)/gi, '$1$2');

//Attempt to fix date range errors txt.value=txt.value.replace(/ ([0-3][\d]|[\d])(?:st|nd|rd|th|) (January|February|March|April|May|June|July|August|September|October|November|December)(?:-|–)([0-3][\d]|[\d])(?:st|nd|rd|th|),? /gi, ' $1-$3 $2 '); txt.value=txt.value.replace(/ (January|February|March|April|May|June|July|August|September|October|November|December),? ([0-3][\d]|[\d])(?:-|–)([0-3][\d]|[\d])(?:st|nd|rd|th|),? /gi, ' $2-$3 $1 ');

//change deprecated birth and death templates txt.value=txt.value.replace(/(\{\{(?:Birth|Death|release)[^}]*)\|mf=ye?s?/gi, '$1'); txt.value=txt.value.replace(/(\{\{(?:Birth|Death|release)[^|]*\|)/gi, '$1df=yes|'); txt.value=txt.value.replace(/(\{\{(?:Birth|Death|release)[^|]*\|)df=ye?s?\|([^}]*df=ye?s?)/gi, '$1$2'); //txt.value=txt.value.replace(/(\{\{(?:Birth|Death|release)\sdate[^}]*)\|mf=ye?s?/gi, '$1'); //txt.value=txt.value.replace(/(\{\{(?:Birth|Death|release)\sdate[^}]*\|)/gi, '$1df=yes|'); //txt.value=txt.value.replace(/(\{\{(?:Birth|Death|release)\|)/gi, '$1df=yes|'); //txt.value=txt.value.replace(/(\{\{(?:Birth|Death|release)\|)df=ye?s?\|([^}]*df=ye?s?)/gi, '$1$2'); //txt.value=txt.value.replace(/(\{\{(?:Birth|Death|release)\sdate[^}]*\|)/gi, '$1df=yes|'); //txt.value=txt.value.replace(/(\{\{(?:Birth|Death|release)\sdate[^}]*\|)df=ye?s?\|([^}]*df=ye?s?)/gi, '$1$2');

//delink ISO //delink_ISO_to_dmy;

} else { //change to mdy //HideText ht = new HideText(true, false, true);

//. ..

//text = ht.Hide(\);

// Month dd     txt.value = txt.value.replace(monthday, "$1 $2, $3"); txt.value = txt.value.replace(daymonth, "$2 $1, $3"); txt.value = txt.value.replace(monthday2, "$1 $2"); txt.value = txt.value.replace(daymonth2, "$2 $1");

//change deprecated dts2 template txt.value=txt.value.replace(/\{\{dts2\|(.*?)\|(.*?)\|(.*?)\}\}/gi, '\{\{dts|link=off|$3|$2|$1\}\}'); //fix dts template txt.value=txt.value.replace(/(\{\{dts\|)/gi, '$1link=off|'); txt.value=txt.value.replace(/(\{\{dts\|)link=off\|([^}]*link=off)/gi, '$1$2');

//change deprecated birth and death templates txt.value=txt.value.replace(/(\{\{(?:Birth|Death|release)[^}]*)\|df=ye?s?/gi, '$1'); txt.value=txt.value.replace(/(\{\{(?:Birth|Death|release)[^|]*\|)/gi, '$1mf=yes|'); txt.value=txt.value.replace(/(\{\{(?:Birth|Death|release)[^|]*\|)mf=ye?s?\|([^}]*mf=yes)/gi, '$1$2'); //txt.value=txt.value.replace(/(\{\{(?:Birth|Death|release)\sdate[^}]*)\|df=ye?s?/gi, '$1'); //txt.value=txt.value.replace(/(\{\{(?:Birth|Death|release)\|)/gi, '$1mf=yes|'); //txt.value=txt.value.replace(/(\{\{(?:Birth|Death|release)\|)mf=ye?s?\|([^}]*df=yes)/gi, '$1$2'); //txt.value=txt.value.replace(/(\{\{(?:Birth|Death|release)\sdate[^|]*\|)/gi, '$1mf=yes|'); //txt.value=txt.value.replace(/(\{\{(?:Birth|Death|release)\sdate[^|]*\|)mf=ye?s?\|([^}]*mf=ye?s?)/gi, '$1$2');

//Attempt to fix date range errors txt.value=txt.value.replace(/ ([0-3][\d]|[\d])(?:st|nd|rd|th|)(?:-|–)(January|February|March|April|May|June|July|August|September|October|November|December) ([0-3][\d]|[\d])(?:st|nd|rd|th|),? /gi, ' $2 $1-$3 '); txt.value=txt.value.replace(/ ([0-3][\d]|[\d])(?:st|nd|rd|th|)(?:-|–)([0-3][\d]|[\d])(?:st|nd|rd|th|) (January|February|March|April|May|June|July|August|September|October|November|December),? /gi, ' $3 $1-$2 ');

//delink ISO //delink_ISO_to_mdy;

// do your work //text = ht.AddBack(\); }

} function LMaddDLinks { var daymonth = new RegExp("0?([1-3][0-9]|[0-9])(?:st|nd|rd|th|) (January|February|March|April|May|June|July|August|September|October|November|December),? *([0-9][0-9][0-9][0-9])", "g"); var monthday = new RegExp("(January|February|March|April|May|June|July|August|September|October|November|December) 0?([1-3][0-9]|[0-9])(?:st|nd|rd|th|),? *([0-9][0-9][0-9][0-9])", "g"); var daymonth2 = new RegExp("\\[\\[0?([1-3][0-9]|[0-9])(?:st|nd|rd|th|) (January|February|March|April|May|June|July|August|September|October|November|December)\\]\\],? *([0-9][0-9][0-9][0-9])", "g"); var monthday2 = new RegExp("\\[\\[(January|February|March|April|May|June|July|August|September|October|November|December) 0?([1-3][0-9]|[0-9])(?:st|nd|rd|th|)\\]\\],? *([0-9][0-9][0-9][0-9])", "g"); var daymonth3 = new RegExp("([^0-9\[])0?([1-3][0-9]|[0-9])(?:st|nd|rd|th|) (January|February|March|April|May|June|July|August|September|October|November|December)([^0-9\\]])", "g"); var monthday3 = new RegExp("([^0-9\[])(January|February|March|April|May|June|July|August|September|October|November|December) 0?([1-3][0-9]|[0-9])(?:st|nd|rd|th|)([^0-9\\]])", "g"); var txt = document.editform.wpTextbox1; txt.value = txt.value.replace(monthday, "$1 $2, $3"); txt.value = txt.value.replace(daymonth, "$1 $2 $3"); txt.value = txt.value.replace(monthday2, "$1 $2, $3"); txt.value = txt.value.replace(daymonth2, "$1 $2 $3"); txt.value = txt.value.replace(monthday3, "$1$2 $3$4"); txt.value = txt.value.replace(daymonth3, "$1$2 $3$4"); } function LMremDLinks { var daymonth = new RegExp("\\[\\[0?([1-3][0-9]|[0-9])(?:st|nd|rd|th|) (January|February|March|April|May|June|July|August|September|October|November|December)\\]\\],? *\\[\\[([0-9][0-9][0-9][0-9])\\]\\]", "g"); var monthday = new RegExp("\\[\\[(January|February|March|April|May|June|July|August|September|October|November|December) 0?([1-3][0-9]|[0-9])(?:st|nd|rd|th|)\\]\\](?:st|nd|rd|th|),? *\\[\\[([0-9][0-9][0-9][0-9])\\]\\]", "g"); var daymonth3 = new RegExp("\\[\\[0?([1-3][0-9]|[0-9])(?:st|nd|rd|th|) (January|February|March|April|May|June|July|August|September|October|November|December)\\]\\]", "g"); var monthday3 = new RegExp("\\[\\[(January|February|March|April|May|June|July|August|September|October|November|December) 0?([1-3][0-9]|[0-9])(?:st|nd|rd|th|)\\]\\](?:st|nd|rd|th|)", "g"); var txt = document.editform.wpTextbox1; txt.value = txt.value.replace(monthday, "$1 $2, $3"); txt.value = txt.value.replace(daymonth, "$1 $2 $3"); txt.value = txt.value.replace(monthday3, "$1 $2"); txt.value = txt.value.replace(daymonth3, "$1 $2"); }

//function Deprecated { //  var txt = document.editform.wpTextbox1; //txt.value=txt.value.replace(/(image ?= ?)Replace this image f?e?male.svg/gi, '$1'); // Add a tag to the summary box //   var txt = document.editform.wpSummary; //   var summary = "Script-assisted. Units/dates/other"; //	if (txt.value.indexOf(summary) == -1) { //		if (txt.value.match(/[^\*\/\s][^\/\s]?\s*$/)) { //			txt.value += " | "; //		} //		txt.value += summary; //	} //  document.editform.wpDiff.click; //}

function oneclickCombo(option) { protect_dates; //  LMyearinX; LMaddDLinks; LMdayMonth(option); LMremDLinks; all_dates; //run function again because it contains a date range bit LMdayMonth(option); unprotect_dates; // Add a tag to the summary box var txt = document.editform.wpSummary; var summary = "Date audit, script-assisted; see mosnum"; if (txt.value.indexOf(summary) == -1) { if (txt.value.match(/[^\*\/\s][^\/\s]?\s*$/)) { txt.value += " | "; }		txt.value += summary; }  document.editform.wpDiff.click; }

function CommonTerms{ var txt = document.editform.wpTextbox1;

txt.value = txt.value.replace(/\[\[(African?|American?|Asian?|Australian?|Canada|Canadian|China|Chinese|People's\sRepublic\sof\sChina|England|English|Europe|European|France|French|Germany?|Indian?|Ireland|Irish|Italy|Italian|Japan|Japanese|New\sZealand|New\sZealander|North\sAmerican?|Russian?|Scotland|Scottish|South\sAfrican?|South\sAmerican?|South\sKorean?|Spain|Spanish|United Kingdom|U\.K\.|UK|United States|United States of America|U\.S\.|US)\]\]/gi, '$1');

txt.value=txt.value.replace(/\[\[(?:African?|American?|Asian?|Australian?|Canada|Canadian|China|Chinese|People's\sRepublic\sof\sChina|England|English|Europe|European|France|French|Germany?|Indian?|Ireland|Irish|Italy|Italian|Japan|Japanese|New\sZealand|New\sZealander|North\sAmerican?|Russian?|Scotland|Scottish|South\sAfrican?|South\sAmerican?|South\sKorean?|Spain|Spanish|United Kingdom|U\.K\.|UK|United States|United States of America|U\.S\.|US)\|(African?|American?|Asian?|Australian?|Canada|Canadian|China|Chinese|People's\sRepublic\sof\sChina|England|English|Europe|European|France|French|Germany?|Indian?|Ireland|Irish|Italy|Italian|Japan|Japanese|New\sZealand|New\sZealander|North\sAmerican?|Russian?|Scotland|Scottish|South\sAfrican?|South\sAmerican?|South\sKorean?|Spain|Spanish|United Kingdom|U\.K\.|UK|United States|United States of America|U\.S\.|US)\]\]/gi, '$1');

txt.value=txt.value.replace(/\[\[(?:African?|American?|Asian?|Australian?|Canada|Canadian|China|Chinese|People's\sRepublic\sof\sChina|England|English|Europe|European|France|French|Germany?|Indian?|Ireland|Irish|Italy|Italian|Japan|Japanese|New\sZealand|New\sZealander|North\sAmerican?|Russian?|Scotland|Scottish|South\sAfrican?|South\sAmerican?|South\sKorean?|Spain|Spanish|United Kingdom|U\.K\.|UK|United States|United States of America|U\.S\.|US)\s\(?language\)?\|(African?|American?|Asian?|Australian?|Canada|Canadian|China|Chinese|People's\sRepublic\sof\sChina|England|English|Europe|European|France|French|Germany?|Indian?|Ireland|Irish|Italy|Italian|Japan|Japanese|New\sZealand|New\sZealander|North\sAmerican?|Russian?|Scotland|Scottish|South\sAfrican?|South\sAmerican?|South\sKorean?|Spain|Spanish|United Kingdom|U\.K\.|UK|United States|United States of America|U\.S\.|US)\]\]/gi, '$1');

txt.value = txt.value.replace(/\[\[(actor|author|dancer|model|novelist|playwright|poet|politican|record producer|singer|songwriter|writer)\]\]/gi, '$1'); txt.value = txt.value.replace(/\[\[(act)ress\]\]/gi, '$1or'); txt.value = txt.value.replace(/\[\[(dance)\]\](r)/gi, '$1$2'); txt.value = txt.value.replace(/\[\[model \(person\)\|(model)\]\]/gi, '$1');

var txt = document.editform.wpSummary; var summary = "Delink common terms. See: wp:overlink"; if (txt.value.indexOf(summary) == -1) { if (txt.value.match(/[^\*\/\s][^\/\s]?\s*$/)) { txt.value += " | "; }		txt.value += summary; }  document.editform.wpDiff.click; }

$(function {    if(document.forms.editform) {        mw.util.addPortletLink('p-tb', 'javascript:CommonTerms', 'Delink common terms', 't-dmy', 'Regexp common terms', , );        mw.util.addPortletLink('p-tb', 'javascript:run_formatgeneral', 'Add metric units', 'ca-unitfixer', 'Fixes some unit formatting', , ); //        mw.util.addPortletLink('p-tb', 'javascript:Deprecated', 'General changes', 't-dmy', 'Regexp general changes', , );        mw.util.addPortletLink('p-tb', 'javascript:oneclickCombo(1)', 'Delink all dates to dmy', 't-dmy', 'day month', , );        mw.util.addPortletLink('p-tb', 'javascript:oneclickCombo(2)', 'Delink all dates to mdy', 't-mdy', 'month day', , );        mw.util.addPortletLink('p-tb', 'javascript:LMyearinX' , 'Delink year-in-X dates', 't-yearinX',  'Regexp yearinX', , );        mw.util.addPortletLink('p-tb', 'javascript:delink_ISO', 'Delink ISO dates', 'ca-unitfixer', 'Fixes some unit formatting', , ); mw.util.addPortletLink('p-tb', 'javascript:run_part_dates', 'Delink non-full dates', 'ca-unitfixer', 'Fixes some unit formatting', , ); mw.util.addPortletLink('p-tb', 'javascript:combined', 'Delink non-full dates+add metric units', 'ca-unitfixer', 'Fixes some unit formatting', , );

} });