User:Lightmouse/monobook.js/script.js: Difference between revisions

Content deleted Content added
No edit summary
mNo edit summary
 
(538 intermediate revisions by 6 users not shown)
Line 1:
//'''Instructions for installation'''
//Create 'winc' function:
//*EITHER: If you have a [[Special:Mypage/monobook.js|monobook]] already, go to it, click "edit this page", and paste in this string underneath your existing script:
//:<code><nowiki>importScript('User:Lightmouse/monobook.js/script.js');</nowiki></code>
//*OR: If you don't have a monobook.js page, create one using this title:
//:<code><nowiki>[[User:[your username]/monobook.js]]</nowiki></code>
//:Then click on "edit this page" and paste in at the top the "importScript" string you see three lines above here.
//*Hit "Save page".
//*Refresh your cache (instructions at top of monobook).
//*You're ready to start.
 
//'''Applying the script—it's very simple'''
function winc(s) {
//*Go to an article and determine whether US or international format is used. (For this purpose, it's best to have selected "no preferences" for dates in your user preferences, which will display the raw date formats that our readers see. Otherwise, you'll need to check in edit mode.) Occasionally, you'll see that the wrong format is used (check [[Wikipedia:Mosnum#Full_date_formatting|MOSNUM's guidance on this]] carefully).
document.write('<script type="text/javascript" src="'
//*Click on "edit this page". You'll see the list of script commands under "what links here". Click on either "delink all dates to mdy" (US format) or "delink all dates to mdy" (international format).
+ 'http://en.wikipedia.org/w/index.php?title=' + s
//*The diff will automatically appear. Check through the changes you're making before saving them. If there are problems, fix them manually before saving, or cancel.
+ '&action=raw&ctype=text/javascript&dontcountme=s"></script>');
//*Leave a note at the article talk page if editors need to negotiate which format to use, or need to be alerted to any other date-related issues.
//*Click on "Save page": it's done.
 
function make_dates_bold(){
var txt=document.editform.wpTextbox1;
 
//process date ranges containing a hyphen
txt.value=txt.value.replace(/\*\s?((?: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\d?)\s?:\s?/gi, '* \'\'\'$1:\'\'\' ');
 
//process date ranges containing a hyphen
txt.value=txt.value.replace(/\*\s?((?:January|February|March|April|May|June|July|August|September|October|November|December) \d\d?\s?[-–]\s?\d\d?)\s?:\s?/gi, '* \'\'\'$1:\'\'\' ');
 
 
//protect date ranges containing a hyphen
txt.value=txt.value.replace(/\*\s?((?: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\d?)\s?:\s?/gi, '$1xx$2');
txt.value=txt.value.replace(/\*\s?((?:January|February|March|April|May|June|July|August|September|October|November|December) \d\d?\s?)[-–](\s?\d\d?)\s?:\s?/gi, '$1xx$2');
 
 
 
//process dates containing a hyphen
txt.value=txt.value.replace(/\*\s?((?:January|February|March|April|May|June|July|August|September|October|November|December) \d\d?\s?)[-–]\s?/gi, '* \'\'\'$1:\'\'\' ');
 
//unprotect date ranges containing a hyphen
txt.value=txt.value.replace(/\*\s?((?:January|February|March|April|May|June|July|August|September|October|November|December) \d\d?\s?)xx(\s?(?:January|February|March|April|May|June|July|August|September|October|November|December) \d\d?)\s?:\s?/gi, '$1–$2');
txt.value=txt.value.replace(/\*\s?((?:January|February|March|April|May|June|July|August|September|October|November|December) \d\d?\s?)xx(\s?\d\d?)\s?:\s?/gi, '$1–$2');
 
//process other dates
txt.value=txt.value.replace(/\*\s?((?:January|February|March|April|May|June|July|August|September|October|November|December) \d\d?)\s?:\s?/gi, '* \'\'\'$1:\'\'\' ');
 
 
edit_summary();
}
//'winc' function allows buttons to be added toolbar
winc('User:Omegatron/monobook.js/addlink.js');
 
function datesfix_common_errors() {
var txt = document.editform.wpTextbox1;
//first add template
//if (txt.value.search(/\{\{template\}\}/gi) == -1)
//{
//txt.value='\{\{template\}\}\r\n'+txt.value;
//}
 
//month+day piped
//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,42}s(?\sin:th|st|nd|rd|)\s(?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\|([^\|]]{1,30}\|(\d{1,4}s?)\]\]/gi, '\[\[$1\]\]');
txt.value=txt.value.replace(/\[\[(?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\s\d{1,2}(?:th|st|nd|rd|)\|([^\]]{1,30})\]\]/gi, '$1');
 
//fix 'bda' template redirect
txt.value=txt.value.replace(/\{\{bda\|([^}]+)\}\}/gi, '\{\{birth date and age|$1\}\}');
 
txt.value=txt.value.replace(/(\[\[)\s([^\]]*\]\])/gi, '$1$2');
txt.value=txt.value.replace(/(\[\[[^\]\|]*)\s(\]\])/gi, '$1$2');
txt.value=txt.value.replace(/(\[\[[^\]]*\s)\s+([^\]]\]\])/gi, '$1$2');
txt.value=txt.value.replace(/(\[\[[^\]]*\d),(\]\])/gi, '$1$2');
}
 
function part_dates() {
var txt=document.editform.wpTextbox1;
 
fix_common_errors();
 
//remove leading zeros from dts templates
txt.value=txt.value.replace(/(\{\{dts\d?\|[^}]*\|)0([^}]*\}\})/gi, '$1$2');
 
//delink ISO dates
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');
 
//remove templates that links launch year, baseball year etc
// txt.value=txt.value.replace(/\{\{(?:avyear|by|fy|ly|scy|sdy)\|(\d{1,4})\}\}/gi, '$1');
 
//remove dts1 template that links ISO dates
txt.value=txt.value.replace(/\{\{dts1\|(\d{4}-\d\d-\d\d)\}\}/gi, '$1');
 
// 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|centuries)\]\]/gi, '$1century1$2');
// txt.value=txt.value.replace(/\[\[((?:first|second|third|fourth|fifth|sixth|seventh|eighth|ninth|tenth|eleventh|twelfth|thirteenth|fourteenth|fifteenth|sixteenth|seventeenth|eighteenth|nineteenth|twentieth|twenty(?:\s|-)first)(?:\s|-))(?:century|centuries)\s(AD|BC|CE|BCE([^\]]{1,30})\]\]/gi, '$1century1');
 
txt.value=txt.value.replace(/\[\[(\d{1,2}(?:st|nd|rd|th)(?:\s|-))century\]\]/gi, '$1century');
txt.value=txt.value.replace(/\[\[(\d{1,2}(?:stfirst|ndsecond|rdthird|thfourth|fifth|sixth|seventh|eighth|ninth|tenth|eleventh|twelfth|thirteenth|fourteenth|fifteenth|sixteenth|seventeenth|eighteenth|nineteenth|twentieth|twenty(?:\s|-)first)(?:\s|-))(century|centuries)(\sAD|\sBC|\sCE|\sBCE|)\]\]/gi, '$1centuries1$2$3');
txt.value=txt.value.replace(/\[\[\d{1,2}(?:stfirst|ndsecond|rdthird|thfourth|fifth|sixth|seventh|eighth|ninth|tenth|eleventh|twelfth|thirteenth|fourteenth|fifteenth|sixteenth|seventeenth|eighteenth|nineteenth|twentieth|twenty(?:\s|-)first)(?:\s|-)(?:century\|(\d{1,2}centuries)(?:st\sAD|nd\sBC|rd\sCE|\sBCE|th)\|([^\]]{1,30})\]\]/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\|centuries)(\d{1,2}(?:stsAD|nd\sBC|rd\sCE|th)(?:\ssBCE|-))centuries\]\]/gi, '$1centuries1$2$3');
txt.value=txt.value.replace(/\[\[(\d{1,2}(?:st|nd|rd|th)(?:\s|-))(?:century\s|centuries)(AD?:\sAD|BC\sBC|CE\sCE|\sBCE|BCE)\|([^\]]{1,30})\]\]/gi, '$1century $21');
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');
//century - protect '20th Century Fox' and '20th Century Picture' - undone below
txt.value=txt.value.replace(/(20th)\s(Century)\s(Fox|Picture)/gi, '$1xx$2 $3');
//century - upper case 'C' to lower case
txt.value=txt.value.replace(/(\d(?:st|nd|rd|th)(?:\s|-))Century/gi, '$1century');
//century- unprotect '20th Century Fox' and '20th Century Picture'
txt.value=txt.value.replace(/(20th)xx(Century)/gi, '$1 $2');
 
// decades and years
txt.value=txt.value.replace(/\[\[(\d{1,43}0)\'?s\]\]/gig, '$1s');
txt.value=txt.value.replace(/\[\[(\d{1,43})0\'?(s)?\s?|(AD|BC|CE|BCE[^\]]{1,30})\]\]/gig, '$1$2 $3');
txt.value=txt.value.replace(/\[\[(\d{1,43}0)\'?(s)?\s?(?:AD|BC|CE|BCE)\|(\d{1,4})\'?(s)?\]\]/gi, '$1$2 $3');
txt.value=txt.value.replace(/\[\[\d{1,43}0\'?s?\s?(?:AD|BC|CE|BCE)\|([^\d]]{1,430})\'?(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}#[^\|\]{1,30}]+\|((?:January|February|March|April|May|June|July|August|September|October|November|December) \s\d{3,4})\]\]/gi, '\[\[$1\]\]');
txt.value=txt.value.replace(/\[\[((?:January|February|March|April|May|June|July|August|September|October|November|December) \s\d{3,4})\]\]/gi, '$1');
txt.value=txt.value.replace(/\[\[(?:January|February|March|April|May|June|July|August|September|October|November|December)\s\d{3,4}\|([^\]]{1,30})\]\]/gi, '$1');
 
//removed piped years when in full date
//year: temporary change to protect accessyear. Undone below at #1
txt.value=txt.value.replace(/(accessyear\[\[\d{1,2}\s(?:January|February|March|April|May|June|July|August|September|October|November|December)\]\],?=\s?)\[\[)[^\|\]]{1,32}\|(\d{1,4})\]\])/gi, '$1xx1$2xx2');
txt.value=txt.value.replace(/(\[\[(?:January|February|March|April|May|June|July|August|September|October|November|December)\s\d{1,2}\]\],?\s?\[\[)[^\|\]]{1,32}\|(\d{1,4}\]\])/gi, '$1$2');
//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');
 
//remove 'xx' left by other code
//year: now remove unprotected linked years
txt.value=txt.value.replace(/\[\[(\d{1,4}in)xx((?:aviation|baseball|film|literature|comics|ireland))\]\]/gi, '$1 $2');
//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 \s\(time\)\|(Present[^\]]{1,30})\]\]/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[^\]]{1,30})\]\]/gi, '$1');
 
//Identify surprise or 'Easter egg' diversions linking months to year articles.
txt.value=txt.value.replace(/\[\[\d{1,4}#[^\|\]{1,30}]+\|(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?:January|FebFebruary|MarMarch|AprApril|May|JunJune|JulJuly|AugAugust|SepSeptember|OctOctober|NovNovember|DecDecember)\|([^\]]{1,30})\]\]/ggi, '$1');
txt.value=txt.value.replace(/\[\[(Jan\.?:January|FebruaryFeb\.?|MarchMar\.?|AprilApr\.?|May\.?|JuneJun\.?|JulyJul\.?|AugustAug\.?|SeptemberSep\.?|OctoberOct\.?|November|December)Nov\.?|(January|February|March|April|May|June|July|August|September|October|November|DecemberDec\.?)\]\]/gig, '$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) \s(\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) \s\d?\d)\]\](?:th|st|nd|rd)/gi, '\[\[$1\]\]');
txt.value=txt.value.replace(/\[\[(\d?\d)(?:th|st|nd|rd) \s(January|February|March|April|May|June|July|August|September|October|November|December)\]\]/gi, '\[\[$1 $2\]\]');
 
 
 
//MonthSequence containing 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) \s\d?\d)\]\](\s?\-?\s?)\[\[(?:January|February|March|April|May|June|July|August|September|October|November|December) \s\d{1,2}(?:th|st|nd|rd)\|(\d{1,2}(?:th|st|nd|rd))\]\]/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) \s\d?\d)\]\](\s?&[nm]dash;\s?)\[\[(?:January|February|March|April|May|June|July|August|September|October|November|December) \s\d{1,2}(?:th|st|nd|rd)\|(\d{1,2}(?:th|st|nd|rd))\]\]/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) \s\d?\d)\]\](\/)\[\[(?:January|February|March|April|May|June|July|August|September|October|November|December) \s\d{1,2}(?:th|st|nd|rd)\|(\d{1,2}(?:th|st|nd|rd))\]\]/gi, '$1$2$3$4');
 
txt.value=txt.value.replace(/([^\[]{4})\[\[((?:January|February|March|April|May|June|July|August|September|October|November|December) \s\d?\d)\]\](\s?\-?\s?)\[\[(\d{1,2}(?:th|st|nd|rd))\]\]/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) \s\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) \s\d?\d)\]\](\/)\[\[(\d{1,2}(?:th|st|nd|rd))\]\]/gi, '$1$2$3$4');
 
txt.value=txt.value.replace(/([^\[]{4})\[\[(\d?\d) \s(?:January|February|March|April|May|June|July|August|September|October|November|December)\]\](\s?\-?\s?)\[\[(?:January|February|March|April|May|June|July|August|September|October|November|December) \s\d{1,2}(?:th|st|nd|rd)\|(\d{1,2}(?:th|st|nd|rd))\]\]/gi, '$1$2$3$4');
//same again but with ndash instead of hyphen
txt.value=txt.value.replace(/([^\[]{4})\[\[(\d?\d) \s(?:January|February|March|April|May|June|July|August|September|October|November|December)\]\](\s?&[nm]dash;\s?)\[\[(?:January|February|March|April|May|June|July|August|September|October|November|December) \s\d{1,2}(?:th|st|nd|rd)\|(\d{1,2}(?:th|st|nd|rd))\]\]/gi, '$1$2$3$4');
//same again but with slash instead of hyphen
txt.value=txt.value.replace(/([^\[]{4})\[\[(\d?\d) \s(?:January|February|March|April|May|June|July|August|September|October|November|December)\]\](\/)\[\[(?:January|February|March|April|May|June|July|August|September|October|November|December) \s\d{1,2}(?:th|st|nd|rd)\|(\d{1,2}(?:th|st|nd|rd))\]\]/gi, '$1$2$3$4');
 
txt.value=txt.value.replace(/([^\[]{4})\[\[(\d?\d) \s(?:January|February|March|April|May|June|July|August|September|October|November|December)\]\](\s?\-?\s?)\[\[(\d{1,2}(?:th|st|nd|rd))\]\]/gi, '$1$2$3$4');
//same again but with ndash instead of hyphen
txt.value=txt.value.replace(/([^\[]{4})\[\[(\d?\d) \s(?:January|February|March|April|May|June|July|August|September|October|November|December)\]\](\s?&[nm]dash;\s?)\[\[(\d{1,2}(?:th|st|nd|rd))\]\]/gi, '$1$2$3$4');
//same again but with slash instead of hyphen
txt.value=txt.value.replace(/([^\[]{4})\[\[(\d?\d) \s(?:January|February|March|April|May|June|July|August|September|October|November|December)\]\](\/)\[\[(\d{1,2}(?:th|st|nd|rd))\]\]/gi, '$1$2$3$4');
 
// month and day piped
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)\|(s\d{1,2}(?:th|st|nd|rd)\|([^\]]{1,30})\]\]/gi, '$1');
txt.value=txt.value.replace(/\[\[\d{1,2}(?:th|st|nd|rd)\s(?:January|February|March|April|May|June|July|August|September|October|November|December)\|([^\]]{1,30})\]\]/gi, '$1');
txt.value=txt.value.replace(/\[\[(\d{1,2}(?:st|nd|rd|th))\]\]/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');
 
//4 digit years piped
// days of the week in full. Optional plurals
txt.value=txt.value.replace(/\[\[\d{1,4}\|(Mondays?|Tuesdays?|Wednesdays?|Thursdays?|Fridays?|Saturdays?|Sundays?[^\]]{1,30})\]\]/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'.
//full dates with incorrect 'year in'
txt.value=txt.value.replace(/\[\[(Mon|Tue|Tues|Wed|Thu|Thur|Thurs|Fri)\]\]/gi, '$1');
txt.value=txt.value.replace(/(\[\[(Sat?:January|February|March|April|May|June|July|August|September|October|November|December)\s(?:[0123][\d]|[\d])\]\]),\s\[\[(\d{1,4})\sin\s[^\]]{1,32}\]\]/ggi, '$1 $2');
txt.value=txt.value.replace(/(\[\[Mondays(?:[0123][\d]|[\d])\s(Mondays?:January|MonFebruary|March|April|May|June|July|August|September|October|November|December)\]\])\s\[\[(\d{1,4})\sin\s[^\]]{1,32}\]\]/gi, '$1 $2');
txt.value=txt.value.replace(/(\[\[Tuesdays(?:[0123][\d]|[\d])\s(Tuesdays?:January|Tues?February|March|April|May|June|July|August|September|October|November|December)\]\])\s\{\{(?:avyear|by|fy|ly|scy|sdy)\|(\d{1,4})\}\}/gi, '$1 [[$2]]');
txt.value=txt.value.replace(/(\[\[Wednesdays(?\:January|February|March|April|May|June|July|August|September|October|November|December)\s(Wednesdays?:[0123][\d]|Wed[\d])\]\]),\s\{\{(?:avyear|by|fy|ly|scy|sdy)\|(\d{1,4})\}\}/gi, '$1 [[$2]]');
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\|[^\}]{1,30}+\}\}/gi, '$1');
txt.value=txt.value.replace(/(death\s?=\s?)\{\{flagicon\|[^\}]{1,30}+\}\}/gi, '$1');
txt.value=txt.value.replace(/(birth_?place\s?=\s?)\{\{flagicon\|[^\}]{1,30}+\}\}/gi, '$1');
txt.value=txt.value.replace(/(death_?place\s?=\s?)\{\{flagicon\|[^\}]{1,30}+\}\}/gi, '$1');
 
//symbol for 'times'
txt.value=txt.value.replace(/&times;/gi, '×');
 
//symbol for superscript 2 and 3
//txt.value=txt.value.replace(/<sup>2<\/sup>/gi, '²');
//txt.value=txt.value.replace(/<sup>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(/°(\sd)&nbsp;(?:°|deg|degree|degrees)&nbsp;([CF]\W)/g, '°$1&nbsp;°$2');
txt.value=txt.value.replace(/(\d)(?:°|deg|degree|degrees)&nbsp;([CF]\W)/g, '°$1&nbsp;°$2');
txt.value=txt.value.replace(/°(\sd)&nbsp;(?:°|deg|degree|degrees)(celsius[CF]\W)/gig, '$1&nbsp;°C$2');
txt.value=txt.value.replace(/(\d)(?:\s|)(?:°&nbsp;|deg|degree|degrees)(celsius?:\s|)([CF]\W)/gig, '$1 °C$2');
txt.value=txt.value.replace(/(\d)\s?&nbsp;(°\[CF\[Celsius|°C\]\])/ggi, '$1 &nbsp;$2');
txt.value=txt.value.replace(/deg[^(\d)(]?:\s|)(\[CF\[Celsius|°C\]\])/gi, '°$1 $2');
txt.value=txt.value.replace(/deg(\s?d)&nbsp;(\[CF\[Fahrenheit|°F\]\])/gi, '°$1&nbsp;$2');
txt.value=txt.value.replace(/deg&nbsp;(\d)(?:\s|)(\[CF\[Fahrenheit|°F\]\])/gi, '°$1 $2');
txt.value=txt.value.replace(/deg([^\d\(\)\/\\]\s)(-?\d[\d,\.]*)(?:\s|-|&nbsp;|)°?F([CF:;,\.?!]?\s[^\d\(\)\/gi\\])/g, '°$1\{\{convert|$2|°F|°C|abbr=on\}\}$3');
txt.value=txt.value.replace(/degrees?([^\d\(\)\/\\]\s)(-?\d[CF\d,\.]*)(?:\s|-|&nbsp;|)(?:deg|degree|degrees)(?:\s|-|&nbsp;|)Fahrenheit([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '°$1\{\{convert|$2|°F|°C\}\}$3');
txt.value=txt.value.replace(/degrees?&nbsp;([CF])([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '°$1$2');
txt.value=txt.value.replace(/(\d)\s?°&nbsp;([CF])/g, '$1 °$2');
txt.value=txt.value.replace(/(\d)°([CF])/g, '$1 °$2');
txt.value=txt.value.replace(/(\d)°\[\[/g, '$1 °[[');
txt.value=txt.value.replace(/(\d)°&nbsp;(\[\[[CF])/gi, '$1&nbsp;°$2');
txt.value=txt.value.replace(/(\d)(\[\[Celsius|°C\]\])/gi, '$1 $2');
txt.value=txt.value.replace(/(\d)(\[\[Fahrenheit|°F\]\])/gi, '$1 $2');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(-?\d[\d,\.]{0,16})(?:\s|-|&nbsp;|)°?F([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1{{convert|$2|°F|°C|abbr=on}}$3');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(-?\d[\d,\.]{0,16})(?:\s|-|&nbsp;|)(?:deg|degree|degrees)(?:\s|-|&nbsp;|)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,\.]{0,16}*)(?:\s|-|)\[\[(metres|meters|metre|meter)\]\]([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1$2 $3$4');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\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,\.]{0,16}*)(?:\s|-|)m([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1 m$2');
//convert 'metres' to 'm' when in parentheses
txt.value=txt.value.replace(/(\(\d[\d,\.]{0,16}*)(?:\s|-|)(?:metres|meters|metre|meter)(\))/g, '$1 m$2');
txt.value=txt.value.replace(/(\(\d[\d,\.]{0,16}*)&nbsp;(?:metres|meters|metre|meter)(\))/g, '$1&nbsp;m$2');
txt.value=txt.value.replace(/({convert\|\d{1,16}+\|(?:m|ft)[^\}]{0,16}*)\|lk=(?:on|in|out)/g, '$1');
 
//metre per second
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\s|-|)(?:m\/second|m\/sec)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1$2 m/s$3');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)&nbsp;(?:m\/second|m\/sec)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1$2&nbsp;m/s$3');
txt.value=txt.value.replace(/({convert\|\d{1,16}+\|(?:m\s|ft\s)[^\}]{0,16}*)\|lk=(?:on|in|out)/g, '$1');
 
//square metre
txt.value=txt.value.replace(/(\d)(?:\s|-|&nbsp;|)sq(?:\s|\.\s|-|&nbsp;)m([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 m²$2');
txt.value=txt.value.replace(/({convert\|\d{1,16}+\|(?:sqmm2|sqft)[^\}]{0,16}*)\|lk=(?:on|in|out)/g, '$1');
 
// millimetre
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\s|-|)mm([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1$2 mm$3');
 
// centimetre, cubic centimetre
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\s|-|)(cm|cc)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1$2 $3$4');
 
// kilometre
//delink this common unit
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\s|-|)\[\[(kilometres|kilometers|kilometre|kilometer)\]\]([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1$2 $3$4');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16})(?:\s|-|*)&nbsp;\[\[(kilometres|kilometers|kilometre|kilometer)\]\]s([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1$2 &nbsp;$3s3$4');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\s|-|)&nbsp;\[\[(?:kilometres?|kilometers?)\|kilometre|kilometer(km)\]\]([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1$2&nbsp; $3$4');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)&nbsp;\[\[(kilometre?:kilometres?|kilometerkilometers?)\|(km)\]\]s([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1$2&nbsp; $3s3$4');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\s|-|)kms?([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1$2 km$3');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)&nbsp;kms?([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1$2&nbsp;km$3');
txt.value=txt.value.replace(/({convert\|\d{1,16}+\|(?:mi|km)[^\}]{0,16}*)\|lk=(?:on|in|out)/g, '$1');
 
//square kilometre
txt.value=txt.value.replace(/(\d)(\s|-|&nbsp;)\[\[km²\]\]/gi, '$1$2km²');
txt.value=txt.value.replace(/(\d)\s?sq\.?(?:\s|-|&nbsp;|)kms?(\s|\.)/gi, '$1 km²$2');
txt.value=txt.value.replace(/({convert\|\d{1,16}+)00\|ha\|\d(\||})/g, '$1|sqkmkm2$2');
txt.value=txt.value.replace(/({convert\|\d{1,16}+)(\d)000\|ha/g, '$1.$2|sqkmkm2');
txt.value=txt.value.replace(/({convert\|\d{1,16}+)(\d\d)0\|ha\|\d(\||})/g, '$1.$2|sqkmkm2$2');
txt.value=txt.value.replace(/({convert\|\d{1,16}+)(\|sqmid)0\|)ha/g, '$1sqkm1.$2|km2');
txt.value=txt.value.replace(/({convert\|\d{1,16}\|(?:sqkm|sqmi+)[^(\}]{0,16}d\d)\|lk=ha\|\d(?:on\|in|out})/g, '$1.$2|km2$2');
txt.value=txt.value.replace(/({convert\|\d{3,16}+)(\|acred\|d)\|ha/g, '$1sqkm1.$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,\.]{0,16}*)(?:\s|-|)(?:km\/second|km\/sec)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1$2 km/s$3');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)&nbsp;(?:km\/second|km\/sec)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1$2&nbsp;km/s$3');
 
// kilometre per hour
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\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,\.]{0,16}*)&nbsp;(?:km\/hr|km\/ph|kph|kmph|kmh)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1$2&nbsp;km/h$3');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\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,\.]{0,16}*)&nbsp;\[\[(?:km\/hr|km\/ph|kph|kmph|kmh)\]\]([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1$2&nbsp;km/h$3');
 
//millilitre
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\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,\.]{0,16}*)(?:\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,\.]{0,16}*)(?:\s|-|)Hz([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1$2 Hz$3');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\s|-|)kHz([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1$2 kHz$3');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\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,\.]{0,16}*)(?:\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,\.]{0,16}*)(?:\s|-|)\[\[(kilograms?)\]\]([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1$2 $3$4');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)&nbsp;\[\[(kilograms?)\]\]([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1$2&nbsp;$3$4');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\s|-|)grammes([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1$2 grams$3');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\s|-|)gramme([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1$2 gram$3');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\s|-|)(?:kgs?|\[\[kg\]\])([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1$2 kg$3');
txt.value=txt.value.replace(/({convert\|\d{1,16}+\|(?:kg|lb)[^\}]{0,16}*)\|lk=(?:on|in|out)/g, '$1');
 
//foot
//convert 'foot' to 'ft' when in parentheses
txt.value=txt.value.replace(/(\(\d[\d,\.]{0,16}*)(?:\s|-|)(?:feet|foot)(\))/g, '$1 ft$2');
txt.value=txt.value.replace(/(\(\d[\d,\.]{0,16}*)&nbsp;(?:feet|foot)(\))/g, '$1&nbsp;ft$2');
 
//remove trailing period when in parentheses
txt.value=txt.value.replace(/(\(\d[\d,\.]{0,16}*)(?:\s|-|)ft\.(\))/g, '$1 ft$2');
txt.value=txt.value.replace(/(\(\d[\d,\.]{0,16}*)&nbsp;ft\.(\))/g, '$1&nbsp;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)&nbsp;sq\.?&nbsp;(feet|foot|ft)/gi, '$1&nbsp;sq&nbsp;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)&nbsp;square&nbsp;ft/gi, '$1&nbsp;sq&nbsp;ft');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\s|-|&nbsp;|)sq(?:\s|-|&nbsp;|)ft([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|sqft|sqmm2|abbr=on\}\}$3');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\s|-|&nbsp;|)square(?:\s|-|&nbsp;|)feet([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|sqft|sqmm2\}\}$3');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\s|-|&nbsp;|)square(?:\s|-|&nbsp;|)foot([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|sqft|sqmm2|singadj=on\}\}$3');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]{1,16}+)(?:\s|-|&nbsp;|)thousand(?:\s|-|&nbsp;|)(?:sq|square)\.?(?:\s|-|&nbsp;|)ft([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2000|sqft|sqmm2|abbr=on\}\}$3');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]{1,16}+)(?:\s|-|&nbsp;|)thousand(?:\s|-|&nbsp;|)(?:sq|square)\.?(?:\s|-|&nbsp;|)feet([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2000|sqft|sqmm2\}\}$3');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]{1,16}+)(?:\s|-|&nbsp;|)thousand(?:\s|-|&nbsp;|)(?:sq|square)\.?(?:\s|-|&nbsp;|)foot([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2000|sqft|sqmm2|singadj=on\}\}$3');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]{1,16}+)(?:\s|-|&nbsp;|)million(?:\s|-|&nbsp;|)(?:sq|square)\.?(?:\s|-|&nbsp;|)ft([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2000000|sqft|sqmm2|abbr=on\}\}$3');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]{1,16}+)(?:\s|-|&nbsp;|)million(?:\s|-|&nbsp;|)(?:sq|square)\.?(?:\s|-|&nbsp;|)feet([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2000000|sqft|sqmm2\}\}$3');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]{1,16}+)(?:\s|-|&nbsp;|)million(?:\s|-|&nbsp;|)(?:sq|square)\.?(?:\s|-|&nbsp;|)foot([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2000000|sqft|sqmm2|singadj=on\}\}$3');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]{1,16}+)\.(\d)(?:\s|-|&nbsp;|)million(?:\s|-|&nbsp;|)(?:sq|square)\.?(?:\s|-|&nbsp;|)ft([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2$300000|sqft|sqmm2|abbr=on\}\}$4');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]{1,16}+)\.(\d)(?:\s|-|&nbsp;|)million(?:\s|-|&nbsp;|)(?:sq|square)\.?(?:\s|-|&nbsp;|)feet([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2$300000|sqft|sqmm2\}\}$4');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]{1,16}+)\.(\d)(?:\s|-|&nbsp;|)million(?:\s|-|&nbsp;|)(?:sq|square)\.?(?:\s|-|&nbsp;|)foot([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2$300000|sqft|sqmm2|singadj=on\}\}$4');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]{1,16}+)\.(\d\d)(?:\s|-|&nbsp;|)million(?:\s|-|&nbsp;|)(?:sq|square)\.?(?:\s|-|&nbsp;|)ft([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2$30000|sqft|sqmm2|abbr=on\}\}$4');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]{1,16}+)\.(\d\d)(?:\s|-|&nbsp;|)million(?:\s|-|&nbsp;|)(?:sq|square)\.?(?:\s|-|&nbsp;|)feet([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2$30000|sqft|sqmm2\}\}$4');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]{1,16}+)\.(\d\d)(?:\s|-|&nbsp;|)million(?:\s|-|&nbsp;|)(?:sq|square)\.?(?:\s|-|&nbsp;|)foot([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2$30000|sqft|sqmm2|singadj=on\}\}$4');
 
//square foot: singular
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-|&nbsp;|)(?:square\sfoot|\[\[square\sfoot\]\])([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|sqft|m2|adj=on\}\}$3');
 
//square foot: plural
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-|&nbsp;|)(?:square\sfeet|\[\[square\sfeet\]\])([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|sqft|m2\}\}$3');
 
//feet per second
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\s|-|)(?:ft\/second|ft\/sec)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1$2 ft/s$3');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)&nbsp;(?:ft\/second|ft\/sec)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1$2&nbsp;ft/s$3');
//feet per second:plural
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\s|-|&nbsp;|)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,\.]{0,16}*)(?:\s|-|&nbsp;|)foot\sper\ssecond([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|ft/s|m/s|singadj=on\}\}$3');
//feet per second:abbreviated
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\s|-|&nbsp;|)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?|-|&nbsp;|)yds?([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 yd$2');
txt.value=txt.value.replace(/(\d)(?:\s|-|&nbsp;|)sq\.?\s?yds?([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1&nbsp; sq yd$2');
txt.value=txt.value.replace(/sqyd\.?\s?yds?)/gi, 'sq yd)');
txt.value=txt.value.replace(/yd\.\)/gi, 'yd)');
//yards: plural
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\s|-|&nbsp;|)(?:yards|\[\[yard\]\]s|\[\[yards\]\])([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|yd|m\}\}$3');
//yards: singular
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\s|-|&nbsp;|)(?:yard|\[\[yard\]\])([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|yd|m|singadj=on\}\}$3');
//yards: abbreviated
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\s|-|&nbsp;|)yd([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|yd|m|abbr=on\}\}$3');
//yards: in full
txt.value=txt.value.replace(/([^y]\sone(?:\s|-|&nbsp;|)yards?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (1 m)$2');
txt.value=txt.value.replace(/([^y]\stwo(?:\s|-|&nbsp;|)yards?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (2 m)$2');
txt.value=txt.value.replace(/([^y]\sthree(?:\s|-|&nbsp;|)yards?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (3 m)$2');
txt.value=txt.value.replace(/([^y]\sfour(?:\s|-|&nbsp;|)yards?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (4 m)$2');
txt.value=txt.value.replace(/([^y]\sfive(?:\s|-|&nbsp;|)yards?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (5 m)$2');
txt.value=txt.value.replace(/([^y]\ssix(?:\s|-|&nbsp;|)yards?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (5 m)$2');
txt.value=txt.value.replace(/([^y]\sseven(?:\s|-|&nbsp;|)yards?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (6 m)$2');
txt.value=txt.value.replace(/([^y]\seight(?:\s|-|&nbsp;|)yards?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (7 m)$2');
txt.value=txt.value.replace(/([^y]\snine(?:\s|-|&nbsp;|)yards?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (8 m)$2');
txt.value=txt.value.replace(/([^y]\sten(?:\s|-|&nbsp;|)yards?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (9 m)$2');
txt.value=txt.value.replace(/([^y]\seleven(?:\s|-|&nbsp;|)yards?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (10 m)$2');
txt.value=txt.value.replace(/([^y]\stwelve(?:\s|-|&nbsp;|)yards?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (11 m)$2');
txt.value=txt.value.replace(/([^y]\sthirteen(?:\s|-|&nbsp;|)yards?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (12 m)$2');
txt.value=txt.value.replace(/([^y]\sfourteen(?:\s|-|&nbsp;|)yards?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (13 m)$2');
txt.value=txt.value.replace(/([^y]\sfifteen(?:\s|-|&nbsp;|)yards?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (14 m)$2');
txt.value=txt.value.replace(/([^y]\ssixteen(?:\s|-|&nbsp;|)yards?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (15 m)$2');
txt.value=txt.value.replace(/([^y]\sseventeen(?:\s|-|&nbsp;|)yards?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (16 m)$2');
txt.value=txt.value.replace(/([^y]\seighteen(?:\s|-|&nbsp;|)yards?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (16 m)$2');
txt.value=txt.value.replace(/([^y]\snineteen(?:\s|-|&nbsp;|)yards?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (17 m)$2');
txt.value=txt.value.replace(/([^y]\stwenty(?:\s|-|&nbsp;|)yards?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (18 m)$2');
 
// knot
txt.value=txt.value.replace(/(\d)(\s|-|&nbsp;)(?: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, '[[knot (speed)|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|-|&nbsp;|)miles\s(?:at|@)\s([\d\.]{1,9}(?:\s|-|&nbsp;|)knots|\{\{convert)/gi, '$1 nautical miles at $2');
txt.value=txt.value.replace(/(\d)(\s|-|&nbsp;)(?:mi|nm|nmi)\s(?:at|@)\s([\d\.]{1,9}(?:\s|-|&nbsp;|)knots|\{\{convert)/gi, '$1$2nmi at $3');
//nautical mile: plural unlinked
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\s|-|&nbsp;|)nautical(?:\s|-|&nbsp;|)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,\.]{0,16}*)(?:\s|-|&nbsp;|)\[\[nautical(?:\s|-|&nbsp;|)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,\.]{0,16}*)(?:\s|-|&nbsp;|)\[\[nautical(?:\s|-|&nbsp;|)mile\]\]s([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|nmi|km\}\}$3');
//nautical mile: singular unlinked
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\s|-|&nbsp;|)nautical(?:\s|-|&nbsp;|)mile([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|nmi|km|singadj=on\}\}$3');
//nautical mile: singular linked
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\s|-|&nbsp;|)\[\[nautical(?:\s|-|&nbsp;|)mile\]\]([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|nmi|km|singadj=on\}\}$3');
//nautical mile: abbreviated
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\s|-|&nbsp;|)(?:\[\[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|-|&nbsp;|)nautical(?:\s|-|&nbsp;|)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (1.9 km)$2');
txt.value=txt.value.replace(/([^y]\stwo(?:\s|-|&nbsp;|)nautical(?:\s|-|&nbsp;|)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (4 km)$2');
txt.value=txt.value.replace(/([^y]\sthree(?:\s|-|&nbsp;|)nautical(?:\s|-|&nbsp;|)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (6 km)$2');
txt.value=txt.value.replace(/([^y]\sfour(?:\s|-|&nbsp;|)nautical(?:\s|-|&nbsp;|)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (7 km)$2');
txt.value=txt.value.replace(/([^y]\sfive(?:\s|-|&nbsp;|)nautical(?:\s|-|&nbsp;|)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (9 km)$2');
txt.value=txt.value.replace(/([^y]\ssix(?:\s|-|&nbsp;|)nautical(?:\s|-|&nbsp;|)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (11 km)$2');
txt.value=txt.value.replace(/([^y]\sseven(?:\s|-|&nbsp;|)nautical(?:\s|-|&nbsp;|)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (13 km)$2');
txt.value=txt.value.replace(/([^y]\seight(?:\s|-|&nbsp;|)nautical(?:\s|-|&nbsp;|)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (15 km)$2');
txt.value=txt.value.replace(/([^y]\snine(?:\s|-|&nbsp;|)nautical(?:\s|-|&nbsp;|)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (17 km)$2');
txt.value=txt.value.replace(/([^y]\sten(?:\s|-|&nbsp;|)nautical(?:\s|-|&nbsp;|)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (19 km)$2');
txt.value=txt.value.replace(/([^y]\seleven(?:\s|-|&nbsp;|)nautical(?:\s|-|&nbsp;|)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (20 km)$2');
txt.value=txt.value.replace(/([^y]\stwelve(?:\s|-|&nbsp;|)nautical(?:\s|-|&nbsp;|)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (22 km)$2');
txt.value=txt.value.replace(/([^y]\sthirteen(?:\s|-|&nbsp;|)nautical(?:\s|-|&nbsp;|)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (24 km)$2');
txt.value=txt.value.replace(/([^y]\sfourteen(?:\s|-|&nbsp;|)nautical(?:\s|-|&nbsp;|)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (26 km)$2');
txt.value=txt.value.replace(/([^y]\sfifteen(?:\s|-|&nbsp;|)nautical(?:\s|-|&nbsp;|)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (28 km)$2');
txt.value=txt.value.replace(/([^y]\ssixteen(?:\s|-|&nbsp;|)nautical(?:\s|-|&nbsp;|)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (30 km)$2');
txt.value=txt.value.replace(/([^y]\sseventeen(?:\s|-|&nbsp;|)nautical(?:\s|-|&nbsp;|)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (31 km)$2');
txt.value=txt.value.replace(/([^y]\seighteen(?:\s|-|&nbsp;|)nautical(?:\s|-|&nbsp;|)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (33 km)$2');
txt.value=txt.value.replace(/([^y]\snineteen(?:\s|-|&nbsp;|)nautical(?:\s|-|&nbsp;|)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (35 km)$2');
txt.value=txt.value.replace(/([^y]\stwenty(?:\s|-|&nbsp;|)nautical(?:\s|-|&nbsp;|)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (37 km)$2');
 
//knot - plural
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\s|-|&nbsp;|)(?:knots|\[\[knot\s\(speed\)\|(?:knots\]\]|knot\]\]s|kts\]\]|kt\]\]s))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|knotkn|km/h\}\}$3');
//knot - singular
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\s|-|&nbsp;|)(?:knot|\[\[knot\s\(speed\)\|(?:knot|kt|kn)\]\])([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|knotkn|km/h|singadj=on\}\}$3');
//knot - abbreviation
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\s|-|&nbsp;|)(?:kts?|\[\[knot\s\(speed\)\|kts(?:kt|kn)\]\])([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|knotkn|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,\.]*)&nbsp;\[\[(miles?)\]\]([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1$2&nbsp;$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,\.]{0,16}*)(?:\s|-|&nbsp;|)(?:miles|\[\[miles\]\]|\[\[mile\]\]s)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1\{\{convert|$2|mi|km\}\}$3');
//miles: singular
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\s|-|&nbsp;|)(?:mile|\[\[mile\]\])([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1\{\{convert|$2|mi|km|singadj=on\}\}$3');
//miles: abbreviated
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\s|-|&nbsp;|)mi([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1\{\{convert|$2|mi|km|abbr=on\}\}$3');
//miles: in full
txt.value=txt.value.replace(/([^y]\sone(?:\s|-|&nbsp;|)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1 (1.6 km)$2');
txt.value=txt.value.replace(/([^y]\stwo(?:\s|-|&nbsp;|)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1 (3 km)$2');
txt.value=txt.value.replace(/([^y]\sthree(?:\s|-|&nbsp;|)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1 (5 km)$2');
txt.value=txt.value.replace(/([^y]\sfour(?:\s|-|&nbsp;|)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1 (6 km)$2');
txt.value=txt.value.replace(/([^y]\sfive(?:\s|-|&nbsp;|)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1 (8 km)$2');
txt.value=txt.value.replace(/([^y]\ssix(?:\s|-|&nbsp;|)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1 (10 km)$2');
txt.value=txt.value.replace(/([^y]\sseven(?:\s|-|&nbsp;|)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1 (11 km)$2');
txt.value=txt.value.replace(/([^y]\seight(?:\s|-|&nbsp;|)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1 (13 km)$2');
txt.value=txt.value.replace(/([^y]\snine(?:\s|-|&nbsp;|)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1 (14 km)$2');
txt.value=txt.value.replace(/([^y]\sten(?:\s|-|&nbsp;|)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1 (16 km)$2');
txt.value=txt.value.replace(/([^y]\seleven(?:\s|-|&nbsp;|)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1 (18 km)$2');
txt.value=txt.value.replace(/([^y]\stwelve(?:\s|-|&nbsp;|)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1 (19 km)$2');
txt.value=txt.value.replace(/([^y]\sthirteen(?:\s|-|&nbsp;|)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1 (19 km)$2');
txt.value=txt.value.replace(/([^y]\sfourteen(?:\s|-|&nbsp;|)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1 (21 km)$2');
txt.value=txt.value.replace(/([^y]\sfifteen(?:\s|-|&nbsp;|)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1 (24 km)$2');
txt.value=txt.value.replace(/([^y]\sixteen(?:\s|-|&nbsp;|)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1 (26 km)$2');
txt.value=txt.value.replace(/([^y]\sseventeen(?:\s|-|&nbsp;|)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1 (27 km)$2');
txt.value=txt.value.replace(/([^y]\seighteen(?:\s|-|&nbsp;|)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1 (29 km)$2');
txt.value=txt.value.replace(/([^y]\snineteen(?:\s|-|&nbsp;|)miles?)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1 (30 km)$2');
txt.value=txt.value.replace(/([^y]\stwenty(?:\s|-|&nbsp;|)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,\.]{0,16}*)(?:\s|-|&nbsp;|)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|-|&nbsp;|)(mile)/gi, '$1uare $2');
// square mile:plural
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\s|-|&nbsp;|)square(?:\s|-|&nbsp;|)miles([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|sqmi|sqkmkm2\}\}$3');
// square mile:singular
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\s|-|&nbsp;|)square(?:\s|-|&nbsp;|)mile([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|sqmi|sqkmkm2|singadj=on\}\}$3');
// square mile:abbreviated
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\s|-|&nbsp;|)sq(?:\s|-|&nbsp;|)mi([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|sqmi|sqkmkm2|abbr=on\}\}$3');
 
//acre foot:plural
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]{3,16}[+)\.(\d,)(?:\.]{0,16}s|-|&nbsp;|)million(?:\s|-|&nbsp;|)acre(?:\s|-|&nbsp;|)feet([:;,\.?!]?\s[^\d\(\)\/\\])/ggi, '$1\{\{convert|$2$300000|acre feet\}\}$34');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d+)\.(\d)(?:\s|-|&nbsp;|)MAF([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1\{\{convert|$2$300000|acre feet\}\}$4');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d+)\.(\d\d)(?:\s|-|&nbsp;|)million(?:\s|-|&nbsp;|)acre(?:\s|-|&nbsp;|)feet([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2$30000|acre feet\}\}$4');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d+)\.(\d\d)(?:\s|-|&nbsp;|)MAF([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1\{\{convert|$2$30000|acre feet\}\}$4');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d+)(?:\s|-|&nbsp;|)million(?:\s|-|&nbsp;|)acre(?:\s|-|&nbsp;|)feet([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2000000|acre feet\}\}$3');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d+)(?:\s|-|&nbsp;|)MAF([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1\{\{convert|$2000000|acre feet\}\}$3');
 
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-|&nbsp;|)acre(?:\s|-|&nbsp;|)feet([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|acre feet\}\}$3');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-|&nbsp;|)\[\[acre(?:\s|-|&nbsp;|)foot\|acre(?:\s|-|&nbsp;|)feet\]\]([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|acre feet\}\}$3');
//acre foot:singular
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]{3,16}[\d,\.]{0,16}*)(?:\s|-|&nbsp;|)acre(?:\s|-|&nbsp;|)foot([:;,\.?!]?\s[^\d\(\)\/\\])/ggi, '$1\{\{convert|$2|acre feet|singadj=on\}\}$3');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-|&nbsp;|)\[\[acre(?:\s|-|&nbsp;|)foot\|acre(?:\s|-|&nbsp;|)feet\]\]([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|acre feet|adj=on\}\}$3');
//acre foot:abbreviation
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]{3,16}[\d,\.]{0,16}*)(?:\s|-|&nbsp;|)(?:acre|ac\.?)(?:\s|-|&nbsp;|)(?:foot|feet|ft)([:;,\.?!]?\s[^\d\(\)\/\\])/ggi, '$1\{\{convert|$2|acre ft|abbr=on\}\}$3');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-|&nbsp;|)\[\[acre(?:\s|-|&nbsp;|)foot\|acre(?:\s|-|&nbsp;|)ft\]\]([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|acre ft|abbr=on\}\}$3');
 
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-|&nbsp;|)\[\[acre(?:\s|-|&nbsp;|)ft\]\]([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$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|-|&nbsp;|)(?:surface|square)(?:\s|-|&nbsp;|)acre/gi, '$1 acre');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]{1,16}+)(?:\s|-|&nbsp;|)thousand(?:\s|-|&nbsp;|)(?:acres|\[\[acres\]\]|\[\[acre\]\]s)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2000|acre|sqkmkm2\}\}$3');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]{1,16}+)(?:\s|-|&nbsp;|)thousand(?:\s|-|&nbsp;|)(?:acre|\[\[acre\]\])([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2000|acre|sqkmkm2|singadj=on\}\}$3');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]{1,16}+)(?:\s|-|&nbsp;|)million(?:\s|-|&nbsp;|)(?:acres|\[\[acres\]\]|\[\[acre\]\]s)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$20000002|acree6acre|sqkmkm2\}\}$3');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]{1,16}+)(?:\s|-|&nbsp;|)million(?:\s|-|&nbsp;|)(?:acre|\[\[acre\]\])([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$20000002|acree6acre|sqkmkm2|singadj=on\}\}$3');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]{1,16}+)\.(\d)(?:\s|-|&nbsp;|)million(?:\s|-|&nbsp;|)(?:acres|\[\[acres\]\]|\[\[acre\]\]s)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2$300000|acre|sqkmkm2\}\}$4');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]{1,16}+)\.(\d)(?:\s|-|&nbsp;|)million(?:\s|-|&nbsp;|)(?:acre|\[\[acre\]\])([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2$300000|acre|sqkmkm2|singadj=on\}\}$4');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]{1,16}+)\.(\d\d)(?:\s|-|&nbsp;|)million(?:\s|-|&nbsp;|)(?:acres|\[\[acres\]\]|\[\[acre\]\]s)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2$30000|acre|sqkmkm2\}\}$4');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]{1,16}+)\.(\d\d)(?:\s|-|&nbsp;|)million(?:\s|-|&nbsp;|)(?:acre|\[\[acre\]\])([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2$30000|acre|sqkmkm2|singadj=on\}\}$4');
txt.value=txt.value.replace(/([^y]\sone(?:\s|-|&nbsp;|)million(?:\s|-|&nbsp;|)acres?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (4,000 km²)$2');
txt.value=txt.value.replace(/(\sa(?:\s|-|&nbsp;|)million(?:\s|-|&nbsp;|)acres?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (4,000 km²)$2');
txt.value=txt.value.replace(/([^y]\stwo(?:\s|-|&nbsp;|)million(?:\s|-|&nbsp;|)acres?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (8,000 km²)$2');
txt.value=txt.value.replace(/([^y]\sthree(?:\s|-|&nbsp;|)million(?:\s|-|&nbsp;|)acres?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (12,000 km²)$2');
txt.value=txt.value.replace(/([^y]\sfour(?:\s|-|&nbsp;|)million(?:\s|-|&nbsp;|)acres?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (16,000 km²)$2');
txt.value=txt.value.replace(/([^y]\sfive(?:\s|-|&nbsp;|)million(?:\s|-|&nbsp;|)acres?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (20,000 km²)$2');
txt.value=txt.value.replace(/([^y]\ssix(?:\s|-|&nbsp;|)million(?:\s|-|&nbsp;|)acres?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (24,000 km²)$2');
txt.value=txt.value.replace(/([^y]\sseven(?:\s|-|&nbsp;|)million(?:\s|-|&nbsp;|)acres?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (28,000 km²)$2');
txt.value=txt.value.replace(/([^y]\seight(?:\s|-|&nbsp;|)million(?:\s|-|&nbsp;|)acres?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (32,000 km²)$2');
txt.value=txt.value.replace(/([^y]\snine(?:\s|-|&nbsp;|)million(?:\s|-|&nbsp;|)acres?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (36,000 km²)$2');
txt.value=txt.value.replace(/([^y]\sten(?:\s|-|&nbsp;|)million(?:\s|-|&nbsp;|)acres?)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (40,000 km²)$2');
 
//acre:plural
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]{3,16}+\d\d[\d,\.]{0,16}*)(?:\s|-|&nbsp;|)(?:acres|\[\[acres\]\]|\[\[acre\]\]s)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1\{\{convert|$2|acre|sqkmkm2\}\}$3');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d?\d\.\d+|\d?\d)(?:\s|-|&nbsp;|)(?:acres|\[\[acres\]\]|\[\[acre\]\]s)([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1\{\{convert|$2|acre|m2\}\}$3');
 
//acre:singular
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)([\d,]{3,16}+\d\d[\d,\.]{0,16}*)(?:\s|-|&nbsp;|)(?:acre|\[\[acre\]\])([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1\{\{convert|$2|acre|sqkmkm2|singadj=on\}\}$3');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d?\d\.\d+|\d?\d)(?:\s|-|&nbsp;|)(?:acre|\[\[acre\]\])([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1\{\{convert|$2|acre|m2|adj=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,\.]{0,16}*)(?:\s|-|&nbsp;|)pounds?(?:\s|-|&nbsp;|)feet([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1\{\{convert|$2|ft.lbf|N.m\}\}$3');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\s|-|&nbsp;|)foot(?:\s|-|&nbsp;|)pounds([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1\{\{convert|$2|ft.lbf|N.m\}\}$3');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\s|-|&nbsp;|)pound(?:\s|-|&nbsp;|)foot([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1\{\{convert|$2|ft.lbf|N.m|singadj=on\}\}$3');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\s|-|&nbsp;|)foot(?:\s|-|&nbsp;|)pound([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1\{\{convert|$2|ft.lbf|N.m|singadj=on\}\}$3');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\s|-|&nbsp;|)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,\.]{0,16}*)(\s|-|&nbsp;|)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,\.]{0,16}*000)(?:\s|-|&nbsp;|)pounds\sforce([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|lbf|kN\}\}$3');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\s|-|&nbsp;|)pounds\sforce([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|lbf|N\}\}$3');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*000)(?:\s|-|&nbsp;|)pound\sforce([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|lbf|kN|singadj=on\}\}$3');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\s|-|&nbsp;|)pound\sforce([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|lbf|N|singadj=on\}\}$3');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*000)(?:\s|-|&nbsp;|)lbf([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|lbf|kN|abbr=on\}\}$3');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\s|-|&nbsp;|)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\)\|([^\]]{1,30}+)\]\]/gi, '[[pound (mass)|$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)&nbsp;lbs?([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1&nbsp;lb$2');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\s|-|&nbsp;|)lb([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|lb|abbr=on\}\}$3');
//pounds and ounces - plural
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\s|-|&nbsp;|)pounds(?:\s|-|&nbsp;|)(\d[\d,\.]{0,16}*)(?:\s|-|&nbsp;|)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,\.]{0,16}*)(?:\s|-|&nbsp;|)pound(?:\s|-|&nbsp;|)(\d[\d,\.]{0,16}*)(?:\s|-|&nbsp;|)ounces?([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|lb|$3|oz|kg|singadj=on\}\}$4');
//pounds and ounces - abbreviated
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\s|-|&nbsp;|)lbs?\.?,?(?:\s|-|&nbsp;|)(\d[\d,\.]{0,16}*)(?:\s|-|&nbsp;|)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,\.]{0,16}*)(?:\s|-|&nbsp;|)feet\.?(?:\s|-|&nbsp;|)(\d[\d,\.]{0,16}*)(?:\s|-|&nbsp;|)(?: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,\.]{0,16}*)(?:\s|-|&nbsp;|)foot\.?(?:\s|-|&nbsp;|)(\d[\d,\.]{0,16}*)(?:\s|-|&nbsp;|)(?:in|ins|inch|inches)\.?([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|ft|$3|in|m|singadj=on\}\}$4');
//foot and inch: abbreviated
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\s|-|&nbsp;|)ft\.?(?:\s|-|&nbsp;|)(\d[\d,\.]{0,16}*)(?:\s|-|&nbsp;|)(?: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,\.]{0,16}*)(?:\s|-|&nbsp;|)feet([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|ft|m\}\}$3');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]*)(?:\s|-|&nbsp;|)linear(?:\s|-|&nbsp;|)feet([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|ft|m\}\}$3');
//foot: singular
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\s|-|&nbsp;|)foot([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|ft|m|singadj=on\}\}$3');
//foot: abbreviated
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\s|-|&nbsp;|)ft\.?([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|ft|m|abbr=on\}\}$3');
 
//inch: plural
txt.value=txt.value.replace(/([^\Wt'’]\s)(\d[\d,\.]{0,16}*)(?:\s|-|&nbsp;|)inches([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|in|mm\}\}$3');
// inch: plural with number in words
txt.value=txt.value.replace(/([^ty]\sthree(?:\s|-|&nbsp;|)(?:inches|\[\[inches\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (76 mm) $2');
txt.value=txt.value.replace(/([^ty]\sfour(?:\s|-|&nbsp;|)(?:inches|\[\[inches\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (102 mm) $2');
txt.value=txt.value.replace(/([^ty]\sfive(?:\s|-|&nbsp;|)(?:inches|\[\[inches\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (127 mm) $2');
txt.value=txt.value.replace(/([^ty]\ssix(?:\s|-|&nbsp;|)(?:inches|\[\[inches\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (152 mm) $2');
txt.value=txt.value.replace(/([^ty]\sseven(?:\s|-|&nbsp;|)(?:inches|\[\[inches\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (178 mm) $2');
txt.value=txt.value.replace(/([^ty]\seight(?:\s|-|&nbsp;|)(?:inches|\[\[inches\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (203 mm) $2');
txt.value=txt.value.replace(/([^ty]\snine(?:\s|-|&nbsp;|)(?:inches|\[\[inches\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (229 mm) $2');
txt.value=txt.value.replace(/([^ty]\sten(?:\s|-|&nbsp;|)(?:inches|\[\[inches\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (254 mm) $2');
txt.value=txt.value.replace(/([^ty]\seleven(?:\s|-|&nbsp;|)(?:inches|\[\[inches\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (279 mm) $2');
txt.value=txt.value.replace(/([^ty]\stwelve(?:\s|-|&nbsp;|)(?:inches|\[\[inches\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (305 mm) $2');
txt.value=txt.value.replace(/([^ty]\sthirteen(?:\s|-|&nbsp;|)(?:inches|\[\[inches\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (330 mm) $2');
txt.value=txt.value.replace(/([^ty]\sfourteen(?:\s|-|&nbsp;|)(?:inches|\[\[inches\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (356 mm) $2');
txt.value=txt.value.replace(/([^ty]\sfifteen(?:\s|-|&nbsp;|)(?:inches|\[\[inches\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (381 mm) $2');
txt.value=txt.value.replace(/([^ty]\ssixteen(?:\s|-|&nbsp;|)(?:inches|\[\[inches\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (406 mm) $2');
//inch: singular
txt.value=txt.value.replace(/([^\Wt'’]\s)(\d[\d,\.]{0,16}*)(?:\s|-|&nbsp;|)(?:inch|\[\[inch\]\])([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|in|mm|singadj=on\}\}$3');
txt.value=txt.value.replace(/({convert\|\d{1,16}+\|(?:in|mm|cm)[^\}]{0,16}*)\|lk=(?:on|in|out)/g, '$1');
// inch: singular with number in words
txt.value=txt.value.replace(/([^ty]\sthree(?:\s|-|&nbsp;|)(?:inch|\[\[inch\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (76 mm) $2');
txt.value=txt.value.replace(/([^ty]\sfour(?:\s|-|&nbsp;|)(?:inch|\[\[inch\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (102 mm) $2');
txt.value=txt.value.replace(/([^ty]\sfive(?:\s|-|&nbsp;|)(?:inch|\[\[inch\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (127 mm) $2');
txt.value=txt.value.replace(/([^ty]\ssix(?:\s|-|&nbsp;|)(?:inch|\[\[inch\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (152 mm) $2');
txt.value=txt.value.replace(/([^ty]\sseven(?:\s|-|&nbsp;|)(?:inch|\[\[inch\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (178 mm) $2');
txt.value=txt.value.replace(/([^ty]\seight(?:\s|-|&nbsp;|)(?:inch|\[\[inch\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (203 mm) $2');
txt.value=txt.value.replace(/([^ty]\snine(?:\s|-|&nbsp;|)(?:inch|\[\[inch\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (229 mm) $2');
txt.value=txt.value.replace(/([^ty]\sten(?:\s|-|&nbsp;|)(?:inch|\[\[inch\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (254 mm) $2');
txt.value=txt.value.replace(/([^ty]\seleven(?:\s|-|&nbsp;|)(?:inch|\[\[inch\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (279 mm) $2');
txt.value=txt.value.replace(/([^ty]\stwelve(?:\s|-|&nbsp;|)(?:inch|\[\[inch\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (305 mm) $2');
txt.value=txt.value.replace(/([^ty]\sthirteen(?:\s|-|&nbsp;|)(?:inch|\[\[inch\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (330 mm) $2');
txt.value=txt.value.replace(/([^ty]\sfourteen(?:\s|-|&nbsp;|)(?:inch|\[\[inch\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (356 mm) $2');
txt.value=txt.value.replace(/([^ty]\sfifteen(?:\s|-|&nbsp;|)(?:inch|\[\[inch\]\]))([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 (381 mm) $2');
txt.value=txt.value.replace(/([^ty]\ssixteen(?:\s|-|&nbsp;|)(?: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)&nbsp;(horsepower|hp|bhp|ihp|shp)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1&nbsp;$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,\.]{0,16}*)(?:\s|-|&nbsp;|)(?:horsepower|\[\[horsepower\]\])([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|hp\}\}$3');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\s|-|&nbsp;|)(indicated(?:\s|-|&nbsp;|)horsepower)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|ihp\}\}$4');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(\d[\d,\.]{0,16}*)(?:\s|-|&nbsp;|)(hp|bhp|ihp|shp)([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1\{\{convert|$2|$3|abbr=on\}\}$4');
 
txt.value=txt.value.replace(/({convert\|\d{1,16}+\|)horsepower\|/gi, '$1horsepower|');
txt.value=txt.value.replace(/({convert\|\d{1,16}+\|)hp\|/gi, '$1hp|');
txt.value=txt.value.replace(/({convert\|\d{1,16}+\|)bhp\|/gi, '$1bhp|');
txt.value=txt.value.replace(/({convert\|\d{1,16}+\|)ihp\|/gi, '$1ihp|');
txt.value=txt.value.replace(/({convert\|\d{1,16}+\|)shp\|/gi, '$1shp|');
 
// rpm
txt.value=txt.value.replace(/(\d)\s?rpm([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1 rpm$2');
txt.value=txt.value.replace(/(\d)&nbsp;rpm([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1&nbsp;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&nbsp;([KkMmGgTt])?(?:bps|bits\/s|b\/s)([:;,\.?!]?\s[^\d\(\)\/\\])/gig, '$1 bit&nbsp;$2bit/s$23');
txt.value=txt.value.replace(/(\d)&nbsp;([KkMmGgTt])bits?(?:bps|bits\/s|b\/s)sec([:;,\.?!]?\s[^\d\(\)\/\\])/ggi, '$1&nbsp;$2bitbit/s$31');
//txt.value=txt.value.replace(/(\d)&nbsp;bps([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1&nbsp;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\|[^}]{1,16}+km):h/g, '$1/h');
txt.value=txt.value.replace(/({convert\|[^}]{1,16}+mi):h/g, '$1/h');
txt.value=txt.value.replace(/({convert\|[^}]{1,16}+ft):s/g, '$1/s');
txt.value=txt.value.replace(/({convert\|[^}]{1,16}+m):s/g, '$1/s');
 
 
//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{1,16}+),(\d)/g, '$1$2');
txt.value=txt.value.replace(/({convert\|\d{1,16}+),(\d)/g, '$1$2');
txt.value=txt.value.replace(/({convert\|\d{1,16}+),(\d)/g, '$1$2');
txt.value=txt.value.replace(/({convert\|\d{1,16}+),(\d)/g, '$1$2');
txt.value=txt.value.replace(/({convert\|\d{1,16}+),(\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,30}+\)\|([^\]]{1,50})\]\]/gi, '$1');
 
}
 
function run_formatgeneral() {
var txt=document.editform.wpTextbox1;
formatgeneral();
edit_summary();
}
 
 
function delink_year_in_X(){
var txt=document.editform.wpTextbox1;
 
txt.value=txt.value.replace(/\{\{(?:avyear|by|fy|ly|mlby|mlb\syear|scy|sdy)\|(\d{1,4})\}\}/gi, '$1');
txt.value=txt.value.replace(/\[\[\d{1,4}\sin\s\w+\|(\d{1,4})\]\]/gi, "[[$1]]");
 
edit_summary();
}
 
function run_dates() {
var txt = document.editform.wpTextbox1;
dates();
 
var linkmap=[];
// Add a tag to the summary box
function protect_dates(){
var txt = document.editform.wpSummary;
var txt=document.editform.wpTextbox1;
var summary = "[[User:Lightmouse/monobook.js/script.js|Script]] assisted. Units/dates/other";
if (txt.value=txt.indexOfvalue.replace(summary)/Image:[^|]+/gi, == -1function(img) {
linkmap.push(img);
if (txt.value.match(/[^\*\/\s][^\/\s]?\s*$/)) {
return "\x02"+(linkmap.length-1)+"\x03";
txt.value += " | ";
});
}
//protect certain dates
txt.value += summary;
txt.value=txt.value.replace(/(september)\s(11[^\d])/gi, '$1xx$2');
}
txt.value=txt.value.replace(/([^\d]7)\s(july)/gi, '$1xx$2');
txt.value=txt.value.replace(/(\[\[May)\s(1968\]\])/gi, '$1xx$2');
txt.value=txt.value.replace(/(\[\[(?:2300|2000))\s(AD\]\])/gi, '$1xx$2');
txt.value=txt.value.replace(/(\[\[(?:112|911|999))(\]\])/gi, '$1xx$2');
txt.value=txt.value.replace(/(\[\[september)xx(11\]\])/gi, '$1 $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');
txt.value=txt.value.replace(/(\[\[May)xx(1968\]\])/gi, '$1 $2');
txt.value=txt.value.replace(/(\[\[(?:2300|2000))xx(AD]\])/gi, '$1 $2');
txt.value=txt.value.replace(/(\[\[(?:112|911|999))xx(\]\])/gi, '$1$2');
 
txt.value=txt.value.replace(/\x02([0-9]+)\x03/g, function(x, n){
// Press the diff button to check it
return linkmap[n];
document.editform.wpDiff.click()
});
}
addOnloadHook(function () {
if(document.forms.editform) {
addLink('p-cactions', 'javascript:run_dates()', 'dates', 'ca-unitfixer', 'Fixes some unit formatting', '', '');
}
});
 
function run_formatgeneralremove_leading_zeros_from_linked_dates () {
var txt = document.editform.wpTextbox1;
//remove leading zero from linked date
formatgeneral();
txt.value=txt.value.replace(/\[\[(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\s0(\d)(?:th|st|nd|rd|)\]\]/gi, '[[$1 $2]]');
txt.value=txt.value.replace(/\[\[0(\d)(?:th|st|nd|rd|)\s(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\]\]/gi, '[[$1 $2]]');
 
}
// Add a tag to the summary box
 
var txt = document.editform.wpSummary;
function remove_leading_zeros_from_nonlinked_dates () {
var summary = "[[User:Lightmouse/monobook.js/script.js|Script]] assisted. Units/dates/other";
var txt=document.editform.wpTextbox1;
if (txt.value.indexOf(summary) == -1) {
//remove leading zero from nonlinked date
if (txt.value.match(/[^\*\/\s][^\/\s]?\s*$/)) {
txt.value=txt.value.replace(/([^\d][^\w\d])(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\s0(\d)(?:th|st|nd|rd|)(,?\s\d{4})([^\w\d][^\d])/gi, '$1$2 $3$4$5');
txt.value += " | ";
txt.value=txt.value.replace(/([^\d][^\w\d])0(\d)(?:th|st|nd|rd|)\s(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)(\s\d{4})([^\w\d][^\d])/gi, '$1$2 $3$4$5');
}
 
txt.value += summary;
txt.value=txt.value.replace(/([^\d][^\w\d])(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\s0(\d)(?:th|st|nd|rd|)([^\w\d][^\d])/gi, '$1$2 $3$4');
}
txt.value=txt.value.replace(/([^\d][^\w\d])0(\d)(?:th|st|nd|rd|)\s(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)([^\w\d][^\d])/gi, '$1$2 $3$4');
 
// Press the diff button to check it
document.editform.wpDiff.click()
}
addOnloadHook(function () {
if(document.forms.editform) {
addLink('p-cactions', 'javascript:run_formatgeneral()', 'units', 'ca-unitfixer', 'Fixes some unit formatting', '', '');
}
});
 
function combined() {
var txt = document.editform.wpTextbox1;
formatgeneral();
dates();
 
function code_delink_dates_to_dmy () {
var txt=document.editform.wpTextbox1;
protect_dates();
part_dates();
remove_leading_zeros_from_linked_dates ();
 
txt.value=txt.value.replace(/\[\[(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\s(\d?\d)(?:th|st|nd|rd|)\]\],?\s?\[\[(\d{1,4})\]\]/gi, '$2 $1 $3');
txt.value=txt.value.replace(/\[\[(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\s(\d?\d)(?:th|st|nd|rd|)\]\],?\s?(\d{1,4})([^\w\d])/gi, '$2 $1 $3$4');
txt.value=txt.value.replace(/\[\[(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\s(\d?\d)(?:th|st|nd|rd|)\]\]/gi, '$2 $1');
 
txt.value=txt.value.replace(/\[\[(\d?\d)(?:th|st|nd|rd|)\s(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\]\],?\s?\[\[(\d{1,4})\]\]/gi, '$1 $2 $3');
txt.value=txt.value.replace(/\[\[(\d?\d)(?:th|st|nd|rd|)\s(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\]\],?\s?(\d{1,4})([^\w\d])/gi, '$1 $2 $3$4');
txt.value=txt.value.replace(/\[\[(\d?\d)(?:th|st|nd|rd|)\s(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\]\]/gi, '$1 $2');
 
//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: 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]]');
 
//remove dts-simple template that links dates
txt.value=txt.value.replace(/\{\{dts-simple\|(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\|\s?(\d\d?)\|(\d{1,4})\}\}/gi, '$2 $1 $3');
 
//remove dts3 template that links dates
txt.value=txt.value.replace(/\{\{dts3\|(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\|(\d\d?)\|(\d{1,4})\}\}/gi, '$2 $1 $3');
 
//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');
 
//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');
 
unprotect_dates();
 
}
 
function code_delink_dates_to_mdy() {
var txt=document.editform.wpTextbox1;
protect_dates();
part_dates();
remove_leading_zeros_from_linked_dates ();
 
txt.value=txt.value.replace(/\[\[(\d?\d)(?:th|st|nd|rd|)\s(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\]\],?\s?\[\[(\d{1,4})\]\]/gi, '$2 $1, $3');
txt.value=txt.value.replace(/\[\[(\d?\d)(?:th|st|nd|rd|)\s(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\]\],?\s?(\d{1,4})([^\w\d])/gi, '$2 $1, $3$4');
txt.value=txt.value.replace(/\[\[(\d?\d)(?:th|st|nd|rd|)\s(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\]\]/gi, '$2 $1');
 
txt.value=txt.value.replace(/\[\[(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\s(\d?\d)(?:th|st|nd|rd|)\]\],?\s?\[\[(\d{1,4})\]\]/gi, '$1 $2, $3');
txt.value=txt.value.replace(/\[\[(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\s(\d?\d)(?:th|st|nd|rd|)\]\],?\s(\d{1,4})([^\w\d])/gi, '$1 $2, $3$4');
txt.value=txt.value.replace(/\[\[(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\s(\d?\d)(?:th|st|nd|rd|)\]\]/gi, '$1 $2');
 
//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: 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]]');
 
//remove dts-simple template that links dates
txt.value=txt.value.replace(/\{\{dts-simple\|(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\|\s?(\d\d?)\|(\d{1,4})\}\}/gi, '$1 $2, $3');
 
//remove dts3 template that links dates
txt.value=txt.value.replace(/\{\{dts3\|(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\|(\d\d?)\|(\d{1,4})\}\}/gi, '$1 $2, $3');
 
//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=ye?s?)/gi, '$1$2');
 
unprotect_dates();
 
}
 
function button_delink_dates_to_dmy() {
code_delink_dates_to_dmy();
edit_summary();
}
 
 
function button_delink_dates_to_mdy() {
code_delink_dates_to_mdy();
edit_summary();
}
 
 
function all_dates_to_dmy(){
var txt=document.editform.wpTextbox1;
protect_dates();
part_dates();
code_delink_dates_to_dmy();
remove_leading_zeros_from_nonlinked_dates ();
//repeat protect dates because 'unprotect dates' function is within 'delink dates' function
protect_dates();
 
txt.value=txt.value.replace(/([^\d][^\w\d])(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\s([0123]?\d)(?:th|st|nd|rd|),?\s(\d{1,4})([^\w\d][^\d])/gi, '$1$3 $2 $4$5');
txt.value=txt.value.replace(/([^\d][^\w\d])(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\s([0123]?\d)(?:th|st|nd|rd|)([^\w\d][^\d])/gi, '$1$3 $2$4');
 
//repeat previous two bits of code to capture some date ranges that were missed first time round
txt.value=txt.value.replace(/([^\d][^\w\d])(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\s([0123]?\d)(?:th|st|nd|rd|),?\s(\d{1,4})([^\w\d][^\d])/gi, '$1$3 $2 $4$5');
txt.value=txt.value.replace(/([^\d][^\w\d])(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\s([0123]?\d)(?:th|st|nd|rd|)([^\w\d][^\d])/gi, '$1$3 $2$4');
 
//Month+day_number "March 7th" -> "March 7"
txt.value=txt.value.replace(/([^\d][^\w\d])([0123]?\d)(?:th|st|nd|rd|)\s(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\s(\d{1,4})([^\w\d][^\d])/gi, '$1$2 $3 $4$5');
txt.value=txt.value.replace(/([^\d][^\w\d])([0123]?\d)(?:th|st|nd|rd|)\s(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)([^\w\d][^\d])/gi, '$1$2 $3$4');
 
 
//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: 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]]');
 
unprotect_dates();
 
edit_summary();
}
 
function all_dates_to_mdy(){
var txt=document.editform.wpTextbox1;
protect_dates();
part_dates();
code_delink_dates_to_mdy();
remove_leading_zeros_from_nonlinked_dates ();
//repeat protect dates because 'unprotect dates' function is within 'delink dates' function
protect_dates();
 
txt.value=txt.value.replace(/([^\d][^\w\d])([0123]?\d)(?:th|st|nd|rd|)\s(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\s(\d{1,4})([^\w\d][^\d])/gi, '$1$3 $2, $4$5');
txt.value=txt.value.replace(/([^\d][^\w\d])([0123]?\d)(?:th|st|nd|rd|)\s(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)([^\w\d][^\d])/gi, '$1$3 $2$4');
 
//repeat previous two bits of code to capture some date ranges that were missed first time round
txt.value=txt.value.replace(/([^\d][^\w\d])([0123]?\d)(?:th|st|nd|rd|)\s(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\s(\d{1,4})([^\w\d][^\d])/gi, '$1$3 $2, $4$5');
txt.value=txt.value.replace(/([^\d][^\w\d])([0123]?\d)(?:th|st|nd|rd|)\s(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)([^\w\d][^\d])/gi, '$1$3 $2$4');
 
//Month+day_number "March 7th" -> "March 7"
txt.value=txt.value.replace(/([^\d][^\w\d])(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\s([0123]?\d)(?:th|st|nd|rd|)(,?\s)(\d{1,4})([^\w\d][^\d])/gi, '$1$2 $3$4$5$6');
txt.value=txt.value.replace(/([^\d][^\w\d])(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\s([0123]?\d)(?:th|st|nd|rd|)([^\w\d][^\d])/gi, '$1$2 $3$4');
 
//add comma when missing
txt.value=txt.value.replace(/([^\d][^\w\d])(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\s([0123]?\d)(?:th|st|nd|rd|)(\s)(\d{1,4})([^\w\d][^\d])/gi, '$1$2 $3,$4$5$6');
 
 
//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: 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]]');
 
unprotect_dates();
 
edit_summary();
}
 
function edit_summary(){
// Add a tag to the summary box
var txt = document.editform.wpSummary;
var summary = "[[Userwp:Lightmouse/monobook.js/script.js|Scriptdatescript]] -assisted. Unitsdate/dates/otherterms audit; see [[wp:unlinkdates]], [[wp:overlink]]";
if (txt.value.indexOf(summary) == -1) {
if (txt.value.match(/[^\*\/\s][^\/\s]?\s*$/)) {
Line 749 ⟶ 1,027:
txt.value += summary;
}
document.editform.wpDiff.click();
}
 
function delink_dates_to_dmy_and_common_terms() {
code_delink_dates_to_dmy();
CommonTerms();
edit_summary();
}
 
function delink_dates_to_mdy_and_common_terms() {
code_delink_dates_to_mdy();
CommonTerms();
edit_summary();
}
 
function CommonTerms(){
var txt=document.editform.wpTextbox1;
 
txt.value=txt.value.replace(/\[\[(African?|Alaskan?|American?|Antarctican?|Arctic\sOcean|Asian?|Atlantic\sOcean|Australian?|Austrian?|Beijing|Belgian|Belgium|Berlin|British|British\sIsles|Canada|Canadian|Central\sAmerican?|Chicago|China|Chinese|Korean?|Paris|People's\sRepublic\sof\sChina|Phillipines|Czech\sRepublic|Danish|Denmark|England|English|Europe|European|France|French|Finland|Finnish|Germany?|Great\sBritain|Greece|Greek|Hawaiin?|Hungary|Hungarian|Hong\sKong|Indian?|Indian\sOcean|Ireland|Irish|Italy|Italian|Japan|Japanese|London|Los\sAngeles|Mexican|Mexico|Mexico\sCity|Middle\sEast|Middle\sEastern|Moscow|the\sNetherlands|Netherlands|New\sDelhi|New\sYork|New\sYork\sCity|New\sZealand|New\sZealander|North\sAmerican?|Norway|Norwegian|Pacific|Pacific\sOcean|Poland|Polish|Portugal|Portuguese|Queensland|Rome|Russian?|Scandinavian?|Scotland|Scottish|Shanghai|South\sAfrican?|Arctic\sOcean|South\sAmerican?|South\sKorean?|Spain|Spanish|Sweden|Swedish|Switzerland|Sydney|Tokyo|Toronto|United\sKingdom|U\.K\.|UK|United\sStates|United\sStates\sof\sAmerica|US|U\.S\.|USA|U\.S\.A\.|Vancouver|Wales|Welsh|Western\sAustralian?|West\sGermany?)\]\]/gi, '$1');
 
txt.value=txt.value.replace(/\[\[(?:African?|Alaskan?|American?|Antarctican?|Arctic\sOcean|Asian?|Atlantic\sOcean|Australian?|Austrian?|Beijing|Belgian|Belgium|Berlin|British|British\sIsles|Canada|Canadian|Central\sAmerican?|Chicago|China|Chinese|Korean?|Paris|People's\sRepublic\sof\sChina|Phillipines|Czech\sRepublic|Danish|Denmark|England|English|Europe|European|France|French|Finland|Finnish|Germany?|Great\sBritain|Greece|Greek|Hawaiin?|Hungary|Hungarian|Hong\sKong|Indian?|Indian\sOcean|Ireland|Irish|Italy|Italian|Japan|Japanese|London|Los\sAngeles|Mexican|Mexico|Mexico\sCity|Middle\sEast|Middle\sEastern|Moscow|the\sNetherlands|Netherlands|New\sDelhi|New\sYork|New\sYork\sCity|New\sZealand|New\sZealander|North\sAmerican?|Norway|Norwegian|Pacific|Pacific\sOcean|Poland|Polish|Portugal|Portuguese|Queensland|Rome|Russian?|Scandinavian?|Scotland|Scottish|Shanghai|South\sAfrican?|Arctic\sOcean|South\sAmerican?|South\sKorean?|Spain|Spanish|Sweden|Swedish|Switzerland|Sydney|Tokyo|Toronto|United\sKingdom|U\.K\.|UK|United\sStates|United\sStates\sof\sAmerica|US|U\.S\.|USA|U\.S\.A\.|Vancouver|Wales|Welsh|Western\sAustralian?|West\sGermany?)\|(African?|Alaskan?|American?|Antarctican?|Arctic\sOcean|Asian?|Atlantic\sOcean|Australian?|Austrian?|Beijing|Belgian|Belgium|Berlin|British|British\sIsles|Canada|Canadian|Central\sAmerican?|Chicago|China|Chinese|Korean?|Paris|People's\sRepublic\sof\sChina|Phillipines|Czech\sRepublic|Danish|Denmark|England|English|Europe|European|France|French|Finland|Finnish|Germany?|Great\sBritain|Greece|Greek|Hawaiin?|Hungary|Hungarian|Hong\sKong|Indian?|Indian\sOcean|Ireland|Irish|Italy|Italian|Japan|Japanese|London|Los\sAngeles|Mexican|Mexico|Mexico\sCity|Middle\sEast|Middle\sEastern|Moscow|the\sNetherlands|Netherlands|New\sDelhi|New\sYork|New\sYork\sCity|New\sZealand|New\sZealander|North\sAmerican?|Norway|Norwegian|Pacific|Pacific\sOcean|Poland|Polish|Portugal|Portuguese|Queensland|Rome|Russian?|Scandinavian?|Scotland|Scottish|Shanghai|South\sAfrican?|Arctic\sOcean|South\sAmerican?|South\sKorean?|Spain|Spanish|Sweden|Swedish|Switzerland|Sydney|Tokyo|Toronto|United\sKingdom|U\.K\.|UK|United\sStates|United\sStates\sof\sAmerica|US|U\.S\.|USA|U\.S\.A\.|Vancouver|Wales|Welsh|Western\sAustralian?|West\sGermany?)\]\]/gi, '$1');
 
txt.value=txt.value.replace(/\[\[(?:African?|Alaskan?|American?|Antarctican?|Arctic\sOcean|Asian?|Atlantic\sOcean|Australian?|Austrian?|Beijing|Belgian|Belgium|Berlin|British|British\sIsles|Canada|Canadian|Central\sAmerican?|Chicago|China|Chinese|Korean?|Paris|People's\sRepublic\sof\sChina|Phillipines|Czech\sRepublic|Danish|Denmark|England|English|Europe|European|France|French|Finland|Finnish|Germany?|Great\sBritain|Greece|Greek|Hawaiin?|Hungary|Hungarian|Hong\sKong|Indian?|Indian\sOcean|Ireland|Irish|Italy|Italian|Japan|Japanese|London|Los\sAngeles|Mexican|Mexico|Mexico\sCity|Middle\sEast|Middle\sEastern|Moscow|the\sNetherlands|Netherlands|New\sDelhi|New\sYork|New\sYork\sCity|New\sZealand|New\sZealander|North\sAmerican?|Norway|Norwegian|Pacific|Pacific\sOcean|Poland|Polish|Portugal|Portuguese|Queensland|Rome|Russian?|Scandinavian?|Scotland|Scottish|Shanghai|South\sAfrican?|Arctic\sOcean|South\sAmerican?|South\sKorean?|Spain|Spanish|Sweden|Swedish|Switzerland|Sydney|Tokyo|Toronto|United\sKingdom|U\.K\.|UK|United\sStates|United\sStates\sof\sAmerica|US|U\.S\.|USA|U\.S\.A\.|Vancouver|Wales|Welsh|Western\sAustralian?|West\sGermany?)\s\(?language\)?\|(African?|Alaskan?|American?|Antarctican?|Arctic\sOcean|Asian?|Atlantic\sOcean|Australian?|Austrian?|Beijing|Belgian|Belgium|Berlin|British|British\sIsles|Canada|Canadian|Central\sAmerican?|Chicago|China|Chinese|Korean?|Paris|People's\sRepublic\sof\sChina|Phillipines|Czech\sRepublic|Danish|Denmark|England|English|Europe|European|France|French|Finland|Finnish|Germany?|Great\sBritain|Greece|Greek|Hawaiin?|Hungary|Hungarian|Hong\sKong|Indian?|Indian\sOcean|Ireland|Irish|Italy|Italian|Japan|Japanese|London|Los\sAngeles|Mexican|Mexico|Mexico\sCity|Middle\sEast|Middle\sEastern|Moscow|the\sNetherlands|Netherlands|New\sDelhi|New\sYork|New\sYork\sCity|New\sZealand|New\sZealander|North\sAmerican?|Norway|Norwegian|Pacific|Pacific\sOcean|Poland|Polish|Portugal|Portuguese|Queensland|Rome|Russian?|Scandinavian?|Scotland|Scottish|Shanghai|South\sAfrican?|Arctic\sOcean|South\sAmerican?|South\sKorean?|Spain|Spanish|Sweden|Swedish|Switzerland|Sydney|Tokyo|Toronto|United\sKingdom|U\.K\.|UK|United\sStates|United\sStates\sof\sAmerica|US|U\.S\.|USA|U\.S\.A\.|Vancouver|Wales|Welsh|Western\sAustralian?|West\sGermany?)\]\]/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(/\[\[(actress)\]\]/gi, '$1');
txt.value=txt.value.replace(/\[\[(dance)\]\](r)/gi, '$1$2');
txt.value=txt.value.replace(/\[\[model\s\(person\)\|(model)\]\]/gi, '$1');
 
edit_summary();
// Press the diff button to check it
document.editform.wpDiff.click()
}
 
$.when(mw.loader.using(['mediawiki.util']), $.ready).done(function () {
addOnloadHook(function () {
if(document.forms.editform) {
addLinkmw.util.addPortletLink('p-cactionstb', 'javascript:combinedCommonTerms()', 'dates+unitsDelink common terms', 'cat-unitfixerdelinkcommon', 'Fixes someRegexp unitcommon formattingterms', '', '');
mw.util.addPortletLink('p-tb', 'javascript:run_formatgeneral()', 'Add metric units', 't-addmetric', 'Fixes some unit formatting', '', '');
}
mw.util.addPortletLink('p-tb', 'javascript:button_delink_dates_to_dmy()', 'Delink dates to dmy', 't-delinkdmy', 'day month', '', '');
mw.util.addPortletLink('p-tb', 'javascript:button_delink_dates_to_mdy()', 'Delink dates to mdy', 't-delinkmdy', 'month day', '', '');
mw.util.addPortletLink('p-tb', 'javascript:all_dates_to_dmy()', 'All dates to dmy', 't-alldmy', 'day month', '', '');
mw.util.addPortletLink('p-tb', 'javascript:all_dates_to_mdy()', 'All dates to mdy', 't-allmdy', 'month day', '', '');
mw.util.addPortletLink('p-tb', 'javascript:delink_year_in_X()' , 'Delink year-in-X dates', 't-yearinX', 'Regexp yearinX', '', '');
mw.util.addPortletLink('p-tb', 'javascript:delink_dates_to_dmy_and_common_terms()', 'Delink dates to dmy+common terms', 't-dmyandcommon', 'Fixes some unit formatting', '', '');
mw.util.addPortletLink('p-tb', 'javascript:delink_dates_to_mdy_and_common_terms()', 'Delink dates to mdy+common terms', 't-mdyandcommon', 'Fixes some unit formatting', '', '');
mw.util.addPortletLink('p-tb', 'javascript:make_dates_bold()', 'Make dates bold', 't-bolddates', 'Fixes some unit formatting', '', '');
}
});