Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
//<pre><code>
//
// Based on: User:Trilobite/Tools, User:Omegatron/monobook.js/replacetab.js
function regExp() {
    var s = prompt("Search regexp?");
    if(s) {
        var r = prompt("Replace regexp?");
        if(!r && r != '') return;
        var txt = document.editform.wpTextbox1;
        txt.value = txt.value.replace(new RegExp(s, "g"), r);
    }
}

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

function emptyParm() {
   var txt = document.editform.wpTextbox1;
   txt.value = txt.value.replace(/\|[\n]*[ ]*[a-zA-Z][a-zA-Z0-9_ ]*=[ ]*[\n]*[ ]*\|/g, "|");
   txt.value = txt.value.replace(/\|[\n]*[ ]*[a-zA-Z][a-zA-Z0-9_ ]*=[ ]*[\n]*[ ]*}}/g, "}}");
}

function unspRefs() {
   var txt = document.editform.wpTextbox1;
   txt.value = txt.value.replace(/(<ref[^>/]*>)[ ]*/g, "$1");
   txt.value = txt.value.replace(/(<ref[^>]*\/>)[ ]*([A-Za-z0-9[\(])/g, "$1 $2");
   txt.value = txt.value.replace(/[ ]*<\/ref>[ ]*([A-Za-z0-9[\(])/g, "</ref> $1");
   txt.value = txt.value.replace(/(<ref[^>]*\/>)[ ]*([\n\]\)])/g, "$1$2");
   txt.value = txt.value.replace(/[ ]*<\/ref>[ ]*([\n\]\)])/g, "</ref>$1");
   txt.value = txt.value.replace(/\{\{[ ]*/g, "{{");
   txt.value = txt.value.replace(/[ ]*}}/g, "}}");

   txt.value = txt.value.replace(/\[\[ ?([^\]\|]*?) ?\]\]/g, "[[$1]]");    // space in links
   txt.value = txt.value.replace(/\[\[ ?([^\]\|]*?) ?\| ?([^\] ][^\]]*?) ?\]\]/g, "[[$1|$2]]");

   txt.value = txt.value               //whitespace
    .replace(/\t/g, " ")
    .replace(/^ ? ? \n/gm, "\n")
    .replace(/(\n\n)\n+/g, "$1")
    .replace(/== ? ?\n\n==/g, "==\n==")
    .replace(/\n\n(\* ?\[?http)/g, "\n$1")
    .replace(/^ ? ? \n/gm, "\n")
    .replace(/\n\n\*/g, "\n*")
    .replace(/[ \t][ \t]+([^= ])/g, " $1")   // .replace(/[ \t][ \t]+/g, " ")
    .replace(/([=\n]\n)\n+/g, "$1")
    .replace(/ \n/g, "\n")              //ending sections
    .replace(/[ ]+,/g, ",")              //before commas
    .replace(/([^\.])[ ]+\. ([^\.])/g, "$1. $2");              //before periods, avoid spaced ellipsis
    //.replace(/,/g, ", ")              //after commas

}

function fixHTML() {
   var txt = document.editform.wpTextbox1;

   txt.value = txt.value               //whitespace
    .replace(/\t/g, " ")
    .replace(/^ ? ? \n/gm, "\n")
    .replace(/(\n\n)\n+/g, "$1")
    .replace(/== ? ?\n\n==/g, "==\n==")
    .replace(/\n\n(\* ?\[?http)/g, "\n$1")
    .replace(/^ ? ? \n/gm, "\n")
    .replace(/\n\n\*/g, "\n*")
    .replace(/[ \t][ \t]+([^= ])/g, " $1")   // .replace(/[ \t][ \t]+/g, " ")
    .replace(/([=\n]\n)\n+/g, "$1")
    .replace(/ \n/g, "\n")              //ending sections 

   //spacing, XHTML
   //.replace(/<([bh])r\s*\/?\s*>/gi, '<$1r />') 
    //.replace(/<br\s*\/?\s*>/gi, '<br />')
    //.replace(/<hr\s*\/?\s*>/gi, '<hr />')
    .replace(/<br\s*\/?\s*>/gi, '<br>')
    .replace(/<hr\s*\/?\s*>/gi, '<hr>')
    .replace(/<ref/gi, '<ref')
    .replace(/<\/ref>/gi, '</ref>')
    .replace(/<references\s*\/?\s*>/gi, '<references />')
    .replace(/<(\/?)TABLE/g, '<$1table')
    .replace(/<(\/?)DIV/g, '<$1div')
    .replace(/<(\/?)SPAN/g, '<$1span')

   //repair bad internal links
    // problems:  .replace(/([^\[]|^)\[?\[([^\]]*?)\]\]?([^\]]|$)/gm, "$1[[$2]]$3")
    // problem w/cats:     .replace(/\[\[ ?([^\]]*?) ?\]\]/g, "[[$1]]")
    .replace(/\[\[ ?([^\]\|]*?) ?\]\]/g, "[[$1]]")
    .replace(/\[\[ ?([^\]\|]*?) ?\| ?([^\] ][^\]]*?) ?\]\]/g, "[[$1|$2]]")
    .replace(/\[\[([^\]]*?)( |_)#([^\]]*?)\]\]/g, "[[$1#$3]]")
    //.replace(/\[\[([^\]\|]+)\|([^\]\|]+)\]\]([A-Za-z\'][A-Za-z]*)([\.\,\;\:\"\!\?\s\n])/g, "[[$1|$2$3]]$4")
    .replace(/\[\[([^\]\|]+)\|([^\]\|]*[^\]\|\'])\]\]([A-Za-z\'][A-Za-z]*)([\.\,\;\:\"\!\?\s\n])/g, "[[$1|$2$3]]$4")

   //repair bad external links
    .replace(/\[?\[http:\/\/([^\]]*?)\]\]?/gi, "[http://$1]")
    .replace(/\[http:\/\/([^\]]*?)\|([^\]]*?)\]/gi, "[http://$1 $2]")
   // and https:
    .replace(/\[?\[https:\/\/([^\]]*?)\]\]?/gi, "[https://$1]")
    .replace(/\[https:\/\/([^\]]*?)\|([^\]]*?)\]/gi, "[https://$1 $2]")

    .replace(/\[http:\/\/en\.wikipedia\.org\/wiki\/([^ ]*) ([^\]]*)\]/gi, "[[$1]]");
}

function formTemp() {
   var txt = document.editform.wpTextbox1;
   txt.value = txt.value.replace(/[ ]*\|[ ]*\n/g, "\n|");
   txt.value = txt.value.replace(/\n\|[ ]*/g, "\n|");
}

function formTem2() {
   var txt = document.editform.wpTextbox1;
   txt.value = txt.value.replace(/\n[ ]*\|[ ]*([^-\|\}])/g, "\n| $1");
}

function defSort() {
   var txt = document.editform.wpTextbox1;
   txt.value = txt.value.replace(/(\[Category:[^\|]*)\|[^ \]][^\]]*\]/g, "$1]");
}

function unSmart() {
   var txt = document.editform.wpTextbox1;
   txt.value = txt.value.replace(/[”“]/g, '"').replace(/[‘’]/g, "'");
}

// function spPuncs() {
//    var txt = document.editform.wpTextbox1;
//    txt.value = txt.value.replace(/,[ ]*/g, ", ").replace(/\.[ ]*([A-Z])/g, ". $1");
//    txt.value = txt.value.replace(/, ([\n\)\]])/g, ",$1").replace(/\. ([\n\)\]])/g, ".$1");
//    txt.value = txt.value.replace(/\. JPG/g, ".JPG").replace(/\. GIF/g, ".GIF").replace(/\. SVG/g, ".SVG");
// }

function staCombo() {
   soloYears();
   //emptyParm();
   unspRefs();
   fixHTML();
   unSmart()
}

function wards() {
   var txt = document.editform.wpTextbox1;
   txt.value = txt.value.replace(/style="text-align:center;background: #[Dd][Dd][Ff][Ff][Dd][Dd];vertical-align: middle;"\|[ ]*([^\n]*)/g, "{{won|$1}}");
   txt.value = txt.value.replace(/style="text-align:center;background: #[Ff][Ff][Dd][Dd][Dd][Dd];vertical-align: middle;"\|[ ]*([^\n]*)/g, "{{nom|$1}}");
   txt.value = txt.value.replace(/style="text-align:center;background: #[Dd][Dd][Ff][Ff][Dd][Dd]"\|[ ]*([^\n]*)/g, "{{won|$1}}");
   txt.value = txt.value.replace(/style="text-align:center;background: #[Ff][Ff][Dd][Dd][Dd][Dd]"\|[ ]*([^\n]*)/g, "{{nom|$1}}");
   txt.value = txt.value.replace(/align="center" style="background: #[Dd][Dd][Ff][Ff][Dd][Dd]"\|[  ']*Won[']*/g, "{{won}}");
   txt.value = txt.value.replace(/align="center" style="background: #[Ff][Ff][Dd][Dd][Dd][Dd]"\|[ ]*Nominated/g, "{{nom}}");
   txt.value = txt.value.replace(/style="background: #[Dd][Dd][Ff][Ff][Dd][Dd]"\|[  ']*Won[']*/g, "{{won}}");
   txt.value = txt.value.replace(/style="background: #[Ff][Ff][Dd][Dd][Dd][Dd]"\|[ ]*Nominated/g, "{{nom}}");
}

$(function () {
    if(document.forms.editform) {
        mw.util.addPortletLink('p-tb', 'javascript:regExp()'   , 'Regexp replace'   , 't-regexp',   'Regexp replace', '', '');
        mw.util.addPortletLink('p-tb', 'javascript:staCombo()' , 'DeusXL'           , 't-staCombo', 'Regexp combo', '', '');
        mw.util.addPortletLink('p-tb', 'javascript:soloYears()', '+DElink \[\[Year]]', 't-solo',    'Regexp years', '', '');
        mw.util.addPortletLink('p-tb', 'javascript:unSmart()' ,  '+Unsmartquote'    , 't-unsmart',  'Regexp unsmart quote', '', '');
        mw.util.addPortletLink('p-tb', 'javascript:unspRefs()' , '+Space cites'     , 't-unspRefs', 'Regexp unspace refs', '', '');
        mw.util.addPortletLink('p-tb', 'javascript:fixHTML()' ,  '+XHTML/Links'     , 't-fixHTML',  'Regexp HTML/spacing', '', '');
        // mw.util.addPortletLink('p-tb', 'javascript:spPuncs()' ,  'Space puncts.'    , 't-spPuncs',  'Regexp space puncs', '', '');
        mw.util.addPortletLink('p-tb', 'javascript:emptyParm()', 'Empty params'     , 't-emptyParm','Regexp unused params', '', '');
        mw.util.addPortletLink('p-tb', 'javascript:formTemp()' , 'Format |template' , 't-formTemp', 'Regexp format temp', '', '');
        mw.util.addPortletLink('p-tb', 'javascript:formTem2()' , 'Format | template', 't-formTem2', 'Regexp format tem2', '', '');
        mw.util.addPortletLink('p-tb', 'javascript:defSort()'  , 'Defsort clear'    , 't-defsort',  'Regexp defsort', '', '');
        mw.util.addPortletLink('p-tb', 'javascript:wards()'    , 'Awards'           , 't-awards','Regexp awards', '', '');
    }
});
//</code></pre>