ব্যবহারকারী:Sajidmahamud835/script/formatgeneral.js

উইকিপিডিয়া, মুক্ত বিশ্বকোষ থেকে

লক্ষ্য করুন: প্রকাশ করার পর, পরিবর্তনগুলো দেখতে আপনাকে আপনার ব্রাউজারের ক্যাশে পরিষ্কার করার প্রয়োজন হতে পারে।

  • ফায়ারফক্স / সাফারি: পুনরায় লোড-এ ক্লিক করার সময় শিফট টিপে ধরে রাখুন, অথবা হয় Ctrl-F5 বা Ctrl-R টিপুন (ম্যাকে ⌘-R টিপুন)
  • গুগল ক্রোম: Ctrl-Shift-R (ম্যাকে ⌘-Shift-R) টিপুন
  • ইন্টারনেট এক্সপ্লোরার / এজ: Ctrl ধরে রাখা অবস্থায় Refresh-এ ক্লিক করুন, অথবা Ctrl-F5 টিপুন
  • অপেরা: Ctrl-F5 টিপুন।
/**
 * TemplateScript adds configurable templates and scripts to the sidebar, and adds an example regex editor.
 * @see https://meta.wikimedia.org/wiki/TemplateScript
 * @update-token [[File:pathoschild/templatescript.js]]
 */
mw.loader.load('//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js');

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

//html, superscripted ordinals 
	regex(/\[\[[\w]*_\d{4}#\d{4}_[\w]*_\d\d?\|(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))( \d\d?)\]\]/g, '$1$2');
//	regex(/<br>/gi, '<br/>');
	regex(/(\d)(<sup>)(m)(\d<\/sup>)/gi, '$1$3$2$4'); //misplaced unit (squared)
	regex(/(\d)(?:<(?:small|sup)>){2}(th|st|nd|rd)(?:<\/(?:small|sup)>){2}/gi, '$1$2');
	regex(/(\d)<(?:small|sup)>(th|st|nd|rd)(?:<\/(?:small|sup)>|<(?:small|sup)\/>)/gi, '$1$2');

//rem linking within section headings
	regex(/(==[ ]?(?:[^\[\n=]*))\[\[([^\|\]]+?)\]\]((?:[^\[=\n]*|)[ ]?==)/gi, '$1$2$3');
	regex(/(==[ ]?(?:[^\[\n=]*))\[\[[^\|\]]+?\|([^\]]+?)\]\]((?:[^\[=\n]*|)[ ]?==)/gi, '$1$2$3');
	regex(/(==[ ]?(?:[^\[\n=]*))\[\[(?:[^\|\]]+?\||)([^\]]+?)\]\]([^\[\|]*)\[\[(?:[^\|\]]+?\||)([^\]]+?)\]\](?:([^\[\|]*)\[\[(?:[^\|\]]+?\||)([^\]]+?)\]\]|)((?:[^\[=\n]*|)[ ]?==)/gi, '$1$2$3$4$5$6$7');
//	regex(/(==[ ]?)\d{1,2}px([^\|\]]+?)((?:[^\[=\n]*|)[ ]?==)/gi, '$1$2$3'); //rem artefact after removing file from title

//rem refs within section headings
	regex(/(==[ ]?(?:[^<>\n]*))(?:<ref(?:>[^<>]*<\/ref| name=[^\/>]+\/)>)([^<>\n]*)(?=[ ]?==)/gi, '$1$2');

//rem linking within persondata fields
	regex(/((?:SHORT DESCRIPTION|(?:DATE|PLACE) OF (?:BIRTH|DEATH)[ ]*=[ ]*)(?:[^\[\]\n]*))\[\[(?:[^\|\]]+?\||)([^\]]+?)\]\]([^\[\]\n}]*)(?=[\n}])/g, '$1$2$3');
	regex(/((?:SHORT DESCRIPTION|(?:DATE|PLACE) OF (?:BIRTH|DEATH)[ ]*=[ ]*)(?:[^\[\]\n]*))\[\[(?:[^\|\]]+?\||)([^\]]+?)\]\]([^\[\]\n}]*)\[\[(?:[^\|\]]+?\||)([^\]]+?)\]\]([^\[\]\n}]*)/g, '$1$2$3$4$5');
	regex(/((?:SHORT DESCRIPTION|(?:DATE|PLACE) OF (?:BIRTH|DEATH)[ ]*=[ ]*)(?:[^\[\]\n]*))\[\[(?:[^\|\]]+?\||)([^\]]+?)\]\]([^\[\]\n}]*)\[\[(?:[^\|\]]+?\||)([^\]]+?)\]\]([^\[\]\n}]*)/g, '$1$2$3$4$5'); //repeat to catch further linking
	regex(/((?:SHORT DESCRIPTION|(?:DATE|PLACE) OF (?:BIRTH|DEATH)[ ]*=[ ]*)(?:[^\[\]\n]*))\[\[(?:[^\|\]]+?\||)([^\]]+?)\]\]([^\[\]\n}]*)(?=[\n}])/g, '$1$2$3'); //repeat to catch further linking (single)


//rem empty parameters
//	regex(/\|[\n]*[ ]*[a-zA-Z][a-z0-9_ ]*=[ ]*[\n]?[ ]*(?=[\|\}])/g, "");

//rem deprecated parameters 
//	regex(/\|\s*influence[sd]\s*=[^\|\{\}]*(?=[\|\}])/g, ""); //rfc infobox person July 2013;	code fails if there are piped links

//add correct hyphenation
	regex(/\b([2-9]|\d{2,3}|half|quarter|two|three|four|five|six|seven|eight|nine|ten) (second|minute|hour|day|week|month|year|decade|fold|liter|litre|degree|inch|foot|yard|mile|meter|metre|man|page|point|word|dollar|cent|floor|store?y|(?:bed|)room)\b/g, "$1-$2");
	regex(/\b([2-9]|\d{2,3}|two|three|four|five|six|seven|eight|nine|ten)-(second[- ]class)\b/g, "$1 $2"); //palliative to reverse incorrectly inserted hyphen "n-second-class"
	regex(/\b(two|three|four|five|six|seven|eight|nine|ten) (halves|thirds|quarters|(?:four|fif|six|seven|eigh|nin|ten)ths)\b/gi, "$1-$2");
	regex(/\b((?:[2-9]|\d{2,3})-(?:month|year)) (old)\b/gi, "$1-$2");
	regex(/(\bnon) ([A-Z]?[a-z]+)/g, "$1-$2");
	regex(/(\bnon)-(grata)/g, "$1 $2"); //reinstate for "persona non grata"
	regex(/(qua non)-([A-Z])/gi, "$1 $2"); //reinstate for "sine qua non"

	regex(/(?:\| ?date= ?)(Cric\w{4,})(?=[|}])/gi, "|publisher=$1");
	regex(/(\|\s*colou?rs\s*=\s*[^{]*){{color ?(?:box|sample)\s?\|#?\w+}}\s?([^{]*){{color ?(?:box|sample)\s?\|#?\w+}}\s?([^{]*){{color ?(?:box|sample)\s?\|#?\w+}}([^{|]*)(?=\n?[|}])/gi, "$1$2$3$4");
	regex(/(\|\s*colou?rs\s*=\s*[^{]*){{color ?(?:box|sample)\s?\|#?\w+}}\s?([^{]*){{color ?(?:box|sample)\s?\|#?\w+}}([^{|]*)(?=\n?[|}])/gi, "$1$2$3");
	regex(/(\|\s*colou?rs\s*=\s*[^{]*){{color ?sample\s?\|#?\w+}}([^{|]*)(?=\n?[|{}])/gi, "$1$2");

}
 
function Ohc_format_MOSCAPS(){
//WP:AMPERSAND
	regex(/(==[ ]*[^=&\n]* )&( [^=&\n]*)(?=[ ]*=)/g, '$1and$2');
	
//improper capitalisation within section headings
	regex(/(==[ ]*External )(Links)(?=[ ]*=)/g, '$1links');
	regex(/(==[ ]*See )(Also)(?=[ ]*=)/g, '$1also');
	regex(/(==[ ]*)Notable ([A-Z]\w*?)/g, '$1$2');
	regex(/(==[ ]*Box )O(ffice)(?=[ ]*=)/g, '$1o$2');
	regex(/(==[ ]*[\w]+? and )A(wards?|chievements?)(?=[ ]*=)/g, '$1a$2');
	regex(/(==[ ]*[\w\s]+? )A(lbums?)(?=[ ]*=)/g, '$1a$2');
	regex(/(==[ ]*[\w\s]+? )C(areer|hampionships|haracters|hart|ompetitions?|ompositions|redits)(?=[ ]*=)/g, '$1c$2');
	regex(/(==[ ]*[A-Z]\w+ )((?:[A-Z]\w+ |and |)Destinations?)(?=[ ]*=)/g, '$1{{' + 'subst:' + 'lc:$2}}');
	regex(/(==[ ]*[\w\s]+? )E(ducation)(?=[ ]*=)/g, '$1e$2');
	regex(/(==[ ]*[\w\s]+? )F(acilities|ilms?)(?=[ ]*=)/g, '$1f$2');
//	regex(/(==[ ]*[\w\s]+? )G(roups?)(?=[ ]*=)/g, '$1g$2');
	regex(/(==[ ]*[\w\s]+? )L(evels?|ife|istings?)(?=[ ]*=)/g, '$1l$2');
	regex(/(==[ ]*[\w\s]+? )M(ember(?:ship|s?))(?=[ ]*=)/g, '$1m$2');
	regex(/(==[ ]*[\w\s]+? )P(oll(?:ing|s?))(?=[ ]*=)/g, '$1p$2');
	regex(/(==[ ]*[\w\s]+? )R(ankings?|eading|esults?|ecords?|eception|ecognition)(?=[ ]*=)/g, '$1r$2');
	regex(/(==[^=\n]+) +S((?:chedule|creenings?|ummary) ?==)/gi, '$1 s$2');
	regex(/(==[ ]*[\w\s]+? )T(ables?|ournaments|ransport(?:ations?|))(?=[ ]*=)/gi, '$1t$2');
	regex(/(==[ ]*[\w\s]+? )Y(ears)(?=[ ]*=)/g, '$1y$2');
 
	regex(/(==[ ]*Performance )(By \w+)(?=[ ]*=)/g, '$1{{' + 'subst:' + 'lc:$2}}');
	regex(/(==[ ]*Extra )(Preliminary Round)(?=[ ]*=)/g, '$1{{' + 'subst:' + 'lc:$2}}');
	regex(/(==[ ]*Extended )(Playing Squad)(?=[ ]*=)/g, '$1{{' + 'subst:' + 'lc:$2}}');
	regex(/(==[ ]*Wider )(Training [Gg]roup)(?=[ ]*=)/g, '$1{{' + 'subst:' + 'lc:$2}}');
	regex(/(==[ ]*Regular )(Season [Ss]chedule)(?=[ ]*=)/g, '$1{{' + 'subst:' + 'lc:$2}}');
	regex(/(==[ ]*Right )([Oo]f Reply)(?=[ ]*=)/g, '$1{{' + 'subst:' + 'lc:$2}}');
	regex(/(==[ ]*Twin )(Towns(?: [Aa]nd [Ss]ister [Cc]ities|))(?=[ ]*=)/g, '$1{{' + 'subst:' + 'lc:$2}}');
	regex(/(==[ ]*Heraldic )(Items)(?=[ ]*=)/g, '$1items');
	regex(/(==[ ]*Campaign )C(redits)(?=[ ]*=)/g, '$1c$2');
	regex(/(==[ ]*Combat )C(hronicle)(?=[ ]*=)/g, '$1c$2');
 
	regex(/(==\w+) M(atch(?:es|))\b/gi, '$1 m$2');
	regex(/(==\w+)[-–\s]B(acks?)\b/gi, '$1-b$2');
	regex(/(==\w+)[-–\s]E(ight)/gi, '$1-e$2');
	regex(/(==(?:Top|Bottom))[-–\s]H(alf)\b/gi, '$1 h$2');
	regex(/(==(?:Scrum|Fly))[-–\s]H(alf|alves)\b/gi, '$1-h$2');
	regex(/(==\w+)[-–\s]Q(uarters?)\b/gi, '$1-q$2');

// within links and pipes
	regex(/((?:'''|\|)(?:[Hh]alf|[Ff]ull))[-–\s]B(acks?(?:'''|\]\]))/gi, '$1 b$2');
	regex(/((?:'''|\|)\w+)[-–\s]F(orwards?(?:'''|\]\]))/gi, '$1 f$2');
	regex(/((?:'''|\|)(?:[Oo]ne|[Tt]hree|[Ff]our||[Ff]ive))[-–\s]E(ights?(?:'''|\]\]))/gi, '$1-e$2');
	regex(/((?:'''|\|)\w+)[-–\s]H((?:alf|alves)(?:'''|\]\]))/gi, '$1-h$2');
	regex(/((?:'''|\|)(?:[Oo]ne|[Tt]hree|[Ff]our))[-–\s]Q(uarters?(?:'''|\]\]))/gi, '$1-q$2');

	regex(/([^\n]*\[\[)(One Country, Two Systems)(?=\])/g, '$1{{' + 'subst:' + 'lc:$2}}');
	regex(/(\[\[(?:\d{3,4} |)(?:[A-Z][a-z]+ )(?:[A-Z][a-z]+ )*)((?:Race |)Riot|Massacre|Murder|Uprising)(?=s?(?: of \d{3,4}|)\]| \(\d{3,4}\))/g, '$1{{' + 'subst:' + 'lc:$2}}');

//improper capitalisation within infobox strings
	regex(/(, |>|\band )A(cademic|ctor|ctress|ctivist|nimator|rranger|rtist|rt critic|strologer|thlete|uthor)(?= ?[\n,<|])/g, '$1a$2');
	regex(/(, |>|\band )B(allet|iography|roadcaster|usiness(?:wo|)man)(?= ?[\n,<|])/g, '$1b$2');
	regex(/(, |>|\band )C(hef|olumnist|o-\w+|omedian|omposer|onsultant|ritic|urator)(?= ?[\n,<|])/g, '$1c$2');
	regex(/(, |>|\band )D(entist|esigner|j|irector|is[ck] jockey|ocumentary maker|ramatist)(?= ?[\n,<|])/g, '$1d$2');
	regex(/(, |>|\band )E(ditor|ditor[ -]in[ -]chief|ducator|ngineer|ntertainer|ntrepreneur|nvironmentalist|ssayist|xecutive producer|xplorer)(?= ?[\n,<|])/g, '$1e$2');
	regex(/(, |>|\band )F(ashion (?:designer|model)|iction|ilm(?: critic|director|[- ]?maker|producer))(?= ?[\n,<|])/g, '$1f$2');
	regex(/(, |>|\band )G(raphic designer)(?= ?[\n,<|])/g, '$1g$2');
	regex(/(, |>|\band )H(acker|istorian|istorical fiction)(?= ?[\n,<|])/g, '$1h$2');
	regex(/(, |>|\band )J(ournalist)(?= ?[\n,<|])/g, '$1j$2');
	regex(/(, |>|\band )L(awyer|eader|ecturer|ibrarian|iterary editor|yricist)(?= ?[\n,<|])/g, '$1l$2');
	regex(/(, |>|\band )M(ayor|athematician|odel|usician|ulti-instrumentalist)(?= ?[\n,<|])/g, '$1m$2');
	regex(/(, |>|\band )M(usic (?:arranger|composer|critic|director|producer))(?= ?[\n,<|])/g, '$1m$2');
	regex(/(, |>|\band )N(arrator|ovelist)(?= ?[\n,<|])/g, '$1n$2');
	regex(/(, |>|\band )O(rator)(?= ?[\n,<|])/g, '$1o$2');
	regex(/(, |>|\band )P(erformance artist|erformer|hilosopher|hilosophy|hotographer|laywright|oet|oetry|olitical activist|olitician|laywright|riest|resenter|roducer|rofessor|olitical commentator|ublic speaker|ublicist|ublisher|undit)(?= ?[\n,<|])/g, '$1p$2');
	regex(/(, |>|\band )R(ecord producer|eporter)(?= ?[\n,<|])/g, '$1r$2');
	regex(/(, |>|\band )S(ailor|cholar|cientist|creenwriter|culptor|oldier|olicitor|inger.songwriter|ong-?writer|peaker|tockbroker)(?= ?[\n,<|])/g, '$1s$2');
	regex(/(, |>|\band )S(tand[- ]?up) C(omed(?:ian|))(?= ?[\n,<|])/g, '$1s$2 c$3');
	regex(/(, |>|\band )T(eacher|elevision|heatr(?:e|ical) (?:critic|director|producer)|ranslator)(?= ?[\n,<|])/g, '$1t$2');
	regex(/(, |>|\band )V(oice actor)(?= ?[\n,<|])/g, '$1v$2');
	regex(/(, |>|\band )W(riter)(?= ?[\n,<|])/g, '$1w$2');

//rem inappropriate
	regex(/((?:occupation|profession)[ ]*=[^\n]*)(?:, (?:activ|philanthrop)ist|Member of Parliament)([^\n]*\n[ ]*\|)/gi, '$1$2');
//	regex(/((?:occupation|profession)[ ]*=[ ]*)(?:\[\[Dewan Rakyat\|Member of Parliament\]\])([^\n]*\n[ ]*\|)/gi, '$1Politican$2');
	regex(/((?:occupation|profession)[ ]*=[ ]*)(?:(?:\[\[[^|\]]+\||)Member of Parliament\]\])([^\n]*\n[ ]*\|)/gi, '$1Politican$2');

//other improper capitalisation -sports
	regex(/((?:==?|\||\()[ ]*[\w\s]+? )H(eld|istory|onou?rs)(?=[ ]*=)/g, '$1h$2');
	regex(/((?:==?|\||\()[ ]*(?:1st|2nd|3rd|\dth) )M(atch)/g, '$1m$2');
	regex(/((?:==?|\||\()[ ]*(?:1st|2nd|3rd|\dth) )F(inal)/g, '$1f$2');
	regex(/((?:==?|\||\()[ ]*(?:First|Second|Third|Fourth|[1-4](?:st|nd|rd|th)) )Q(uarter)/g, '$1q$2');
	regex(/((?:==?|\||\()[ ]*(?:First|Second|Third|Fourth|[1-4](?:st|nd|rd|th)) )R(ound)/g, '$1r$2');
    regex(/(\W[a-z]+ )[Qq](uarter)[\- ]F(inal)/g, '$1q$2-f$3');
    regex(/((?:==?|\||\()[ ]*[Qq]uarter|[Ss]emi)[\- ]?F(inal)/gi, '$1-f$2');
    regex(/(\W[a-z]+ )[Ss](emi)[\- ]F(inal)/g, '$1s$2-f$3');
	regex(/(==[ ]*Overall )(Team [Rr]ecords?)(?=[ ]*=)/g, '$1{{' + 'subst:' + 'lc:$2}}');
	regex(/(==[ ]*(?:CFL|N[BFH]L) )C(oaching )[Rr](ecords?)(?=[ ]*=)/g, '$1c$2r$3');
	regex(/(==[ ]*[-\w\s]+? )C(areer )S(tatistics)(?=[ ]*=)/g, '$1{{' + 'subst:' + 'lc:$2}}');
	regex(/(==[ ]*[\w\s]+? (?:and |& |))S(eason|quad|tyle|taff|tage|tatistics)(?=[ ]*=)/g, '$1s$2');
    regex(/\b(Bowling |Batting )S(tyle)\b/g, '$1s$2');
	regex(/\b([Rr]ight|[Lr]eft)-([Hh]anded(?: (?:Opening|Top [Oo]rder) Batsman|))\b/gi, '$1-{{' + 'subst:' + 'lc:$2}}');
    regex(/\b([Aa]ll)[- ]R(ounder)\b/gi, '$1-r$2');
    regex(/\b(Wicket)[- ]K(eeper)\b/gi, '$1-k$2');
    regex(/([Rr]ight|[Lr]eft)[- ]([Aa]rm (?:\[\[(?:[^|\[\]]+\||))(?:[Oo]rthodox|(?:[Ll]eg|[Oo]ff)[- ][Ss]pin|[Mm]edium(?: [Ff]ast|)|[Ff]ast(?: [Mm]edium|))\]\])/g, '$1-{{' + 'subst:' + 'lc:$2}}');
    regex(/((?:\[\[[^|\[\]]+\|)(?:[Rr]ight|[Lr]eft))[- ]([Aa]rm (?:[Oo]rthodox|(?:[Ll]eg|[Oo]ff)[- ][Ss]pin|[Mm]edium(?: [Ff]ast|)|[Ff]ast(?: [Mm]edium|))\]\])/g, '$1-{{' + 'subst:' + 'lc:$2}}');
    regex(/\b(Fast)[-– ]([Mm]edium [Bb]owler)\b/g, '$1–{{' + 'subst:' + 'lc:$2}}');
    regex(/\b([Ff]ast |[Mm]edium )B(owler)\b/g, '$1b$2');
    regex(/\b([Ff]ast|[Ss]low)[-– ]((?:lef|righ)t-[Aa]rm [Bb]owler)\b/g, '$1 {{' + 'subst:' + 'lc:$2}}');
    regex(/\b(fast)[- ]B(owler)\b/g, '$1-b$2');
    regex(/\b([Ll]eg|[Oo]ff)[- ]([Ss](?:pin )(?:Bowler|))\b/g, '$1-{{' + 'subst:' + 'lc:$2}}');
    
	regex(/(== ?\w )(League Table)/gi, '$1 {{' + 'subst:' + 'lc:$2}}');
	regex(/(Contract) +(Detail|Length)/gi, '$1 {{' + 'subst:' + 'lc:$2}}');
	regex(/((?:\||==)\s*Current) +(Club|Line-?up|Roster|Team)/gi, '$1 {{' + 'subst:' + 'lc:$2}}');
	regex(/(Points|Pts) +(Ag(?:ain|)st|Diff(?:erence|)|For)/g, '$1 {{' + 'subst:' + 'lc:$2}}');
	regex(/(== ?Top) +(scorers(?: in Order of League Goals|))/gi, '$1 {{' + 'subst:' + 'lc:$2}}');
	regex(/(== ?Touring )P(arty)/gi, '$1p$2');
	regex(/((?:==|[|!])\s*(?:\d+ Season |Current |Former ))P(layers)/gi, '$1p$2');
	regex(/(== ?\d+ Gains & )L(osses)/gi, '$1l$2');
	regex(/(== ?\d+ Signings & )T(ransfers)/gi, '$1t$2');
	regex(/(== ?\w+) +(Results & Fixtures)/g, '$1 {{' + 'subst:' + 'lc:$2}}');
	regex(/(== ?\w+) +(and Capacity)/g, '$1 {{' + 'subst:' + 'lc:$2}}');
	regex(/(== ?Accidents[^=]+)I(ncidents)/gi, '$1i$2');
	regex(/(Airport) +(Name|Code)/g, '$1 {{' + 'subst:' + 'lc:$2}}');
	regex(/(Bonus )P(oints|ts)/gi, '$1p$2');
	regex(/(Busiest) +((?:International |Domestic |) *(?:Flight|Routes(?: Out [Oo]f|)))/gi, '$1 {{' + 'subst:' + 'lc:$2}}');
	regex(/(City ) ?S(erved)/g, '$1s$2');
	regex(/(br(?: ?\/|)>|Aircraft |Passenger |[Ff]reight )M(ovement)/gi, '$1m$2');
	regex(/(br(?: ?\/|)>|Total |Domestic |International )P(assenger)/g, '$1p$2');
	regex(/(Date (?:and|&) )T(ime)/gi, '$1t$2');
	regex(/(\|\s*(?:Date|Years?)) ((?:[Oo]f |)[A-Z]\w+)/g, '$1 {{' + 'subst:' + 'lc:$2}}'); //piping added to exclude false positive: "10 Years Younger"
	regex(/(\|+\s*)Hall \d[\.,] ?/g, '$1'); //rem over-specific location of match
	regex(/(Did) +([Nn]ot (?:[Ee]nter|[Pp]articipate|[Qq]ualify))/g, '$1 {{' + 'subst:' + 'lc:$2}}');
	regex(/(: Estimated [Vv]otes by) +EU P(arty)/gi, '{{' + 'subst:' + 'lc:$1}}EU party');
	regex(/(First|Second|Third|(?:Four|Fif|Six|Seven|Eigh|Nin|Ten|\d)th) +(Places?(?: Match|))/g, '$1 {{' + 'subst:' + 'lc:$2}}');
	regex(/(Group )S(tage)/gi, '$1s$2');
	regex(/(Seasonal )C(harter)/g, '$1c$2');
	regex(/(Term )((?:[Oo]f |)[A-Z]\w+)/g, '$1 {{' + 'subst:' + 'lc:$2}}');
	regex(/(Top )C(arrier)/g, '$1c$2');
	regex(/(Winter |Summer ) ?S(easonal)/g, '$1s$2');
	regex(/(Until the )E(nd of)/gi, '$1e$2');
	regex(/(Former |Last |New |Previous )C(lub)/gi, '$1c$2');
	regex(/(Years |When )S(igned)/gi, '$1s$2');
	regex(/(Match )I(nformation)/gi, '$1i$2');
	regex(/(\|\s*\w+ )S(taff\b)/gi, '$1s$2');
	regex(/N(ational Distribution of Seats)/gi, 'N{{' + 'subst:' + 'lc:$1}}');
	regex(/([-–]\s?Won (?:Gold|Silver|Bronze) Medal)/gi, '{{' + 'subst:' + 'lc:$1}}');

	regex(/(Tour|Test|International) +M(atch)/gi, '$1 m$2');
	regex(/(Oppo)(?:sing [Tt]eam)/g, '$1nent');
	regex(/(by )O(pponent)/g, '$1o$2');
	regex(/(Tournaments(?:<br>| ))(Met)/gi, '$1 {{' + 'subst:' + 'lc:$2}}');
	regex(/(W&ndash;L(?:<br>| ))(Record)/gi, '$1 {{' + 'subst:' + 'lc:$2}}');
	regex(/(Largest(?:<br>| ))(Victory|Defeat)/gi, '$1 {{' + 'subst:' + 'lc:$2}}');
	regex(/(Current(?:<br>| ))(Streak)/gi, '$1 {{' + 'subst:' + 'lc:$2}}');

	regex(/\b(st|nd|rd|th) G(rade)\b/g, '$1 g$2');
//	regex(/(Official )S(ite)/g, '$1s$2');
//	regex(/([A-Z][a-z]+ )O(fficial )W(ebsite\])/g, '$1o$2w$3');
	regex(/(\'Further )R(eading)(?=\')/g, '$1r$2');

        regex(/(\w )A(nd|t) A(n? \w)/g, '$1a$2 a$3');
        regex(/(\w )A(nd|t) (My \w)/g, '$1a$2 $3');
        regex(/(\w )A(nd|t) T(he \w)/g, '$1a$2 t$3');
        regex(/(\w )By A(n? \w)/g, '$1by a$2');
        regex(/(\w )By (My \w)/g, '$1by $2');
        regex(/(\w )By T(he \w)/g, '$1by t$2');
        regex(/(\w )For A(n? \w)/g, '$1for a$2');
        regex(/(\w )For (My \w)/g, '$1for $2');
        regex(/(\w )For T(he \w)/g, '$1for t$2');
        regex(/(\w )In A(n? \w)/g, '$1in a$2');
        regex(/(\w )In (My \w)/g, '$1in $2');
        regex(/(\w )In T((?:he|o) \w)/g, '$1in t$2');
        regex(/(\w )I(nto \w)/g, '$1i$2');
        regex(/(\w )O(f|n|r) A(n? \w)/g, '$1o$2 a$3');
        regex(/(\w )O(f|n|r) (My \w)/g, '$1o$2 $3');
        regex(/(\w )O(f|n|r) T(he \w)/g, '$1o$2 t$3');
        regex(/(\w )To A(n? \w)/g, '$1to a$2');
        regex(/(\w )To (My \w)/g, '$1to m$2');
        regex(/(\w )To T(he \w)/g, '$1to t$2');
        regex(/(\w )With A(n? \w)/g, '$1with a$2');
        regex(/(\w )With M(y \w)/g, '$1with M$2');
        regex(/(\w )With T(he \w)/g, '$1with t$2');

        regex(/(\w )A(t \w)/g, '$1a$2');
        regex(/(\w )I(n \w)/g, '$1i$2');
        regex(/(\w )O([fn] \w)/g, '$1o$2');  //'Or' - false positive (with heraldric Or); 'On' - name (e.g. Ma On Shan)

        regex(/([Rr]unners?)[\- ]U(p\b)/g, '$1-u$2');
        regex(/([Rr]unner)[\- ][Uu](?:ps)\b/g, '$1s-up');
        regex(/([Pp]lay)[\- ][Oo](ffs?)/g, '$1-o$2');

        regex(/(\b\d{4})-P(resent\b)/gi, '$1–p$2');
        regex(/(\b\d{4}) - P(resent\b)/gi, '$1 – p$2');
        regex(/(\b\d{4}(?:–| – ))P(resent\b)/g, '$1p$2');
 
        regex(/(Bring |Turn )[Ii]t o(n)/g, '$1It O$2');   //reverting proper name - title of song or work
        regex(/(Carry )o(n [A-Z]\w*|n film)/g, '$1O$2');   //reverting proper name - 'Carry On' film series
        regex(/(Ma )o(n Shan)/g, '$1O$2');   //reverting proper name - 'Ma On Shan'
        regex(/(NZ |New Zealand )o(n Air|n Screen)/g, '$1O$2');   //reverting proper name - 'NZ On Air'
        regex(/in t(he [Aa]ir [Tt]onight)/g, 'In t$1');   //reverting per "In the Air Tonight"
        regex(/in t(he Flesh [Tt]our)/g, 'In t$1');   //reverting per "In the Flesh tour"
        regex(/(\W)o(n This Day)/g, '$1O$2');   //reverting per "on This Day"
        regex(/({NYT )o(n this day)/g, '$1O$2');   //reverting per "on This Day"
        regex(/(\bWing )o(n\b)/g, '$1O$2');   //reverting "Wing on"
        regex(/(Star Trek )into( Darkness)/g, '$1Into$2');   //reverting proper name - title of work
        regex(/((?:Sonata|Symphony|Concerto|Prelude)(?: No\. \d\d?|)) in a((?:-flat|) [Mm](?:inor|ajor))/g, '$1 in A$2');   //reverting musical term

}
 
function Ohc_format_MOSFLAG(){
    //remove flagicons from country, birth and death
	regex(/((?:birth|death|place|captain|chairman|club|coach|manager|headquarters|citizenship|nationality|occupation|origin|party|stadium)\s*=\s*)(?:\{\{flag ?icon\|[^{}]+(?:\|[^{}]+|)\}\} ?|\[\[(?:File|Image):Flag of [^\]]\]\] ?)/gi, '$1');    
	regex(/((?:birth|death)(?:_?place|)\s*=\s*)\{\{flag(?:country|u|)\|([^{}|]+)(?:\|[^{}]+|)\}\}/gi, '$1$2');
	regex(/((?:(?:birth|death)(?:_?place|)|citizenship|residence|nationality)\s*=\s*)(?:\{\{flag ?icon\|[^{}]+(?:\|[^{}]+|)\}\} ?|\[\[(?:File|Image):Flag of [^\]]+\]\] ?)/gi, '$1$2');
//    regex(/((?:country|location|nationality|residence)\s*=\s*)\{\{flagu?\|([^{}|]+)(?:\|[^{}]+|)\}\}/gi, '$1$2');
//    regex(/((?:country|location|nationality|residence)\s*=\s*)\{\{flag(?:country|)\|([^{}|]+)(?:\|[^{}]+|)\}\}/gi, '$1$2');

//strip bare facilities icons
    regex(/\[\[(File|image):Feature (accessible|elevators|parking|suburban buses)\.svg\|\d\d?px(?:\|[^\]]+)?\]\]\s*/gi, ''); 


//remove scroll bar for reflists 
	regex(/(References ?={1,4}[\n\r])[\r\n\s]*<div class=[^>]*>([\S\s]*?)<\/div>/gi, '$1$2');
//	regex(/((?:Notes ?|References ?)={2,4}\s?[\n\r])[\r\n\s]*(?:\{\{[Rr]eflist\}\}|<[Rr]eferences ?\/>)/gi, '$1{{reflist|colwidth=30em}}');  

}
 
function Ohc_format_MOSPUNCT(){
//rem redundant spaces underlining and punctuation
//	regex(/([\s>()])[“„«](\[?\w+)/gi, '$1\"$2');
	regex(/(.)[“„”«»](.)/gi, '$1\"$2');
//	regex(/([\s>()])[‘`´’′](\[?\w+)/gi, '$1\'$2');
//	regex(/(\w)[‘`´’′](s|t)\b/gi, '$1\'$2');		// in-word replacement of various single quotes and prime symbol with straight apostrophe
	regex(/(.)[‘`´’](.)/gi, '$1\'$2');		// straight apostrophe (won't touch prime symbol here)
	regex(/([\w;,\]\)>] ) +([\[(]|[a-z\d])/gi, '$1$2');	//rem multiple spaces except when preceded by full stop; tweaked to not remove dbl spaces where preceded by new sentence (caps)
	regex(/(^\.U\.)[ ]+((?:S|K)\.)/gi, '$1$2');  //U. S. and U. K. to U.S. and U.K.
	regex(/(<\/?ref(?: name=[^<>\/]*?|)>)[ ,\.]*(<ref)/gi, '$1$2');	// remove punctuation between ref tags
	regex(/[ ]{1,3}(<\/?ref(?:>| >| n))/gi, '$1');		// remove spaces and line feeds preceding ref tags and templates
//	regex(/(<\/ref ?>|<ref name=[^>\/]+\/>)([^\s<])/gi, '$1 $2');		// add spaces after ref tags
//	regex(/[ ]+(\n|\r)/gi, '$1');	//removes multiple spaces preceding line break
	regex(/(\d),&nbsp;([12]\d{3}\b)+/gi, '$1, $2');	//removes nbsp preceding year
	regex(/(\d)(?:&nbsp;| )%/gi, '$1%');	//removes nbsp preceding '%'
	regex(/(&nbsp;)[ ](–|&ndash;)/gi, '$1$2');	//Palliative for dashes script insertion of space after nbsp
	regex(/(&nbsp;| )(?:—|&mdash;)(&nbsp;| )/gi, '$1–$2');	//Palliative for dashes script insertion of space after nbsp

	regex(/\b(US|UK|A(?:US|)|C(?:AN|)|NZ|HK) ([$£¥€])(\d)/g, '$1$2$3');
	regex(/([$£¥€]) (\d)/gi, '$1$2');
	regex(/(\{\{(?:INR|Indian Rupee)\}\}|Rs\.?)(\d+)/g, '$1 $2');
	regex(/\{\{AUD\}\} ?(\d+)/g, 'A$$1');

//rem 'external' wiktionary links
	regex(/\[https?:\/\/en\.wiktionary\.org\/wiki\/[\w]*[ ](\w[^\]]*)\]/gi, '$1');

//rem linked copyright symbol 
	regex(/(\[\[copyright\|©\]\] |©)/gi, '');

//rem leading and lagging spaces within wikilinks
	regex(/(\[\[)[ ]+([^\[\]\|]*?)[ ]*(\]\])/gi, '$1$2$3');
	regex(/(\[\[)[ ]*([^\[\]\|]*?)[ ]+(\]\])/gi, '$1$2$3');
	regex(/(\[\[[^\[\]\|]*?[ ])[ ]+([^\[\]]*?\]\])/gi, '$1$2');
	regex(/(\[\[[^\[\]\|]*?)[ ]+\|[ ]*([^\[\]]+\]\])/gi, '$1|$2');
//	regex(/(\[\[[^\[\]\|]*?)[ ]*\|[ ]+([^\[\]]+\]\])/gi, '$1|$2'); //can't remember why we need the second (repeated) line
 
	regex(/\[\[([^\[\]\(\)\|:]*)( \([^\[\]\(\)\|]*(?:album|film|magazine|newspaper|song)\))(\]\])/gi, '[[$1$2|$1$3'); //adding piping to album|film|magazine dabbed by parentheticals

//symbol for 'times' and dashes
//	regex(/&times;/gi, '×');
//	regex(/([ \.][\d]+)x([\d]+(?:\.[\d]+|)\s)/gi, '$1&nbsp;×&nbsp;$2'); //disabling - never ending false positives
	regex(/(\d) x (\d )/gi, '$1&nbsp;×&nbsp;$2');
	regex(/\s(A[cglmrstu]|B[ahikrad]?|C[adeflmno]|D[bsyrsu]|E[rsu]|F[elmr]?|G[adef]|H[fgos]|I[nr]?|Kr?|L[aruv]|M[dgnot]|N[abdeiop]?|Os?|P[abdmortu]?|R[abefghnu]|S[bcegimnr]?|T[abcehilm]?|U[ub][neopst]|V|W|Xe|Yb?|Z[nr])-(Br|Cl?|F|H|I|N|O|P|Se?)\s/g, ' $1–$2 '); //signifying chemical bonds abbrev
//	regex(/([^<][^!] *)--( *[^>])/gi, '$1–$2'); //disabling - causes false positives with urls and some images
	regex(/&mdash;/gi, '—');
	regex(/([\w\d]) — (?=[\w\d])/gi, '$1 – ');		// tweak to avoid replacing emdashes in strings that are in non-roman unicode characters
	regex(/(\D7\d7)–(\d(?:00|)\D)/gi, '$1-$2');  //airplane model numbers taking hyphen

//inserting a white space between wikilinks to avoid errors upon unlinking
	regex(/(\]\][\.,]?)(\[\[)(?!file|image)/gi, '$1 $2');

//full stop and nbsp fixes
	//protection for strings within wikilinks
	regex(/(\[(?:[^\|\]]*)\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})([ ]*(?:[cgkm])[^\|\]]*?[\|\]])/gi, '$1♭$2');
	regex(/(\[(?:[^\|\]]*)(?:\d?\d[:\.]\d?\d| \d?\d))([ ]*(?:[ap]\.m\.|[ap]m)[^\|\]]*?[\|\]])/gi, '$1♭$2');

	//degrees and titles
	regex(/(Ph)(?:\.\s?|\s)(D)\.?/g, '$1$2');
	regex(/\b(B|M)(?:\.\s?|\s)(Arch|Comm|Ed|Eng|Sc|Tech)\.?(?=\W)/g, '$1$2');
	regex(/(\|[A-Z])\.\s?([A-Z])\.\s?([A-Z])\.\s?([A-Z])\.?\]\]/g, '$1$2$3$4]]');
	regex(/(\|[A-Z])\.\s?([A-Z])\.\s?([A-Z])\.?\]\]/g, '$1$2$3]]');
	regex(/(\|[A-Z])\.\s?([A-Z])\.?\]\]/g, '$1$2]]');

	//times of day, time ranges
//	regex(/((?:\d?\d[:\.]\d?\d| \d?\d)&nbsp;[ap])(?:\.m\.)(?=[^\w\-])/gi, '$1m');

//	regex(/(\d?\d[:\.]\d?\d| \d?\d)(?:[ ]*|&nbsp;)(?:a\.m\.|am)(?:[ ]*|&nbsp;)[-–—](?:[ ]*|&nbsp;)(\d?\d[:\.]\d?\d|\d?\d)(?:[ ]*|&nbsp;)(?:p\.m\.|pm)(?=[^\w\-])/gi, '$1&nbsp;am&nbsp;– $2&nbsp;pm');
//	regex(/(\d?\d[:\.]\d?\d| \d?\d)(?:[ ]*|&nbsp;)(?:p\.m\.|pm)(?:[ ]*|&nbsp;)[-–—](?:[ ]*|&nbsp;)(\d?\d[:\.]\d?\d|\d?\d)(?:[ ]*|&nbsp;)(?:a\.m\.|am)(?=[^\w\-])/gi, '$1&nbsp;pm&nbsp;– $2&nbsp;am');
//	regex(/(\d?\d[:\.]\d?\d| \d?\d)(?:[ ]*|&nbsp;)(?:a\.m\.|am)(?:[ ]*|&nbsp;)[-–—](?:[ ]*|&nbsp;)(\d?\d[:\.]\d?\d|\d?\d)(?:[ ]*|&nbsp;)(?:a\.m\.|am)(?=[^\w\-])/gi, '$1&nbsp;am&nbsp;– $2&nbsp;am');
//	regex(/(\d?\d[:\.]\d?\d| \d?\d)(?:[ ]*|&nbsp;)(?:p\.m\.|pm)(?:[ ]*|&nbsp;)[-–—](?:[ ]*|&nbsp;)(\d?\d[:\.]\d?\d|\d?\d)(?:[ ]*|&nbsp;)(?:p\.m\.|pm)(?=[^\w\-])/gi, '$1&nbsp;pm&nbsp;– $2&nbsp;pm');
//	regex(/(\d?\d[:\.]\d?\d| \d?\d)(?:[ ]*|&nbsp;)(?:a\.m\.|am)(?:[ ]*|&nbsp;)[-–—](?:[ ]*|&nbsp;)(noon|midnight)(?=[^\w\-])/gi, '$1&nbsp;am&nbsp;– $2');
//	regex(/(\d?\d[:\.]\d?\d| \d?\d)(?:[ ]*|&nbsp;)(?:p\.m\.|pm)(?:[ ]*|&nbsp;)[-–—](?:[ ]*|&nbsp;)(noon|midnight)(?=[^\w\-])/gi, '$1&nbsp;pm&nbsp;– $2');
	regex(/\b(\d?\d[:\.]\d?\d| \d?\d)(?:[ ]*|&nbsp;)(?:am|AM)(?=[^\w\-])/g, '$1&nbsp;am');
	regex(/\b(\d?\d[:\.]\d?\d| \d?\d)(?:[ ]*|&nbsp;)(?:pm|PM)(?=[^\w\-])/g, '$1&nbsp;pm');
	regex(/\b(\d?\d[:\.]\d?\d| \d?\d)(?:[ ]*|&nbsp;)(?:[Aa]\.[Mm]\.)(?=\S[^\w\-])/g, '$1&nbsp;am');
	regex(/\b(\d?\d[:\.]\d?\d| \d?\d)(?:[ ]*|&nbsp;)(?:[Pp]\.[Mm]\.)(?=\S[^\w\-])/g, '$1&nbsp;pm');
	regex(/\b(\d?\d[:\.]\d?\d| \d?\d)(?:[ ]*|&nbsp;)(?:[Aa]\.[Mm])(?=\.[\s\W][A-Z])/g, '$1&nbsp;am');
	regex(/\b(\d?\d[:\.]\d?\d| \d?\d)(?:[ ]*|&nbsp;)(?:[Pp]\.[Mm])(?=\.[\s\W][A-Z])/g, '$1&nbsp;pm');
	regex(/\b(\d?\d[:\.]\d?\d| \d?\d)(?:[ ]*|&nbsp;)(?:[Aa]\.[Mm])(?=\.<)/g, '$1&nbsp;am');
	regex(/\b(\d?\d[:\.]\d?\d| \d?\d)(?:[ ]*|&nbsp;)(?:[Pp]\.[Mm])(?=\.<)/g, '$1&nbsp;pm');

	regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*(?:kw)\b/gi, '$1&nbsp;kW');
	regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*(?:khz)\b/gi, '$1&nbsp;kHz');
	regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*(?:mhz)\b/gi, '$1&nbsp;MHz');
	regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*(?:ghz)\b/gi, '$1&nbsp;GHz');
	regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*(?:kph|kphr|kmh|kmhr|kmph|kmphr|km\/hr)\b/gi, '$1&nbsp;km/h');
	regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*(?:m\.p\.h\.)\b/gi, '$1&nbsp;mph');
	regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*(gm|kg|km)s?\b/g, '$1&nbsp;$2');
	regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*KMs?\b/gi, '$1&nbsp;km');
	regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*KGs?\b/gi, '$1&nbsp;kg');
	regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*(?:K(g|m))s?\b/gi, '$1&nbsp;k$2');
	regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*cms?/gi, '$1&nbsp;cm');
//	regex(/([^\|\[=]\d{1,3})\s(m|b|tr)illion(\b[^}])/g, '$1&nbsp;$2illion$3');

        regex(/(\d)(?:&nbsp;|\s)?C(entimet(?:er|re))/g, '$1&nbsp;c$2');
        regex(/(\d)(?:&nbsp;|\s)?K(ilomet(?:er|re))/g, '$1&nbsp;k$2');
        regex(/(\d)(?:&nbsp;|\s)?KM\b/g, '$1&nbsp;km');

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

// Convert degree symbols into ° symbol, ensure preceding space
	regex(/&deg;/g, '°');
//	regex(/º/g, '°');

// Celsius spelling errors
	regex(/(?:celsius|celcius|centigrade)/gi, 'Celsius');

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

// Convert &sup to superscript
//	regex(/(m)(?:&sup2;|²);/gi, '$1<sup>2</sup>');
//	regex(/(m)(?:&sup3;|³);/gi, '$1<sup>3</sup>');

//remove commas from numerical values in convert template
	regex(/(\{convert\|\d+),(\d)/gi, '$1$2');
	regex(/(\{convert\|\d+),(\d)/gi, '$1$2');
	regex(/(\{convert\|\d+),(\d)/gi, '$1$2');
	regex(/(\{convert\|\d+),(\d)/gi, '$1$2');
	regex(/(\{convert\|\d+),(\d)/gi, '$1$2');

//inappropriate unit pairs for convert template
	regex(/(\{\{convert\s*\|\d+(?:\.\d|)\|acre\|)m2(?=[|}])/gi, '$1ha');

//remove leading zeros from convert template
	regex(/(\{\{convert\s*\|)\s*0+(?=[1-9])/gi, '$1$2');

///e-acute accent in spelling
	regex(/\b(caf|clich)e\b/g, '$1é');

}
 
function Ohc_format_MOSHASH(){
//hash fixes
	regex(/([^=] )#(\d{1,3}[,\.]?[<\s])/gi, '$1No. $2');

}
 
function Ohc_format_COMMONALITY(){
///per WP:COMMONALITY
	regex(/([Ff])reshman (year)/g, '$1irst $2');
	regex(/([Ss])ophomore (album|year)/g, '$1econd $2');

//remove Crores and Lakhs in templates converting to USD 
	regex(/\{\{INR Convert[ ]*\|[ ]*/gi, '{{INRConvert|'); //removing spaces (redirects to shortcut)
 
	regex(/(\{INRConvert\|-?\d{2,})8\.[5-9]\d*[ ]*(\|c(?:\|-?\d|)\}\})/gi, '$19$2');
	regex(/(\{INRConvert\|-?\d{2,})7\.[5-9]\d*[ ]*(\|c(?:\|-?\d|)\}\})/gi, '$18$2');
	regex(/(\{INRConvert\|-?\d{2,})6\.[5-9]\d*[ ]*(\|c(?:\|-?\d|)\}\})/gi, '$17$2');
	regex(/(\{INRConvert\|-?\d{2,})5\.[5-9]\d*[ ]*(\|c(?:\|-?\d|)\}\})/gi, '$16$2');
	regex(/(\{INRConvert\|-?\d{2,})4\.[5-9]\d*[ ]*(\|c(?:\|-?\d|)\}\})/gi, '$15$2');
	regex(/(\{INRConvert\|-?\d{2,})3\.[5-9]\d*[ ]*(\|c(?:\|-?\d|)\}\})/gi, '$14$2');
	regex(/(\{INRConvert\|-?\d{2,})2\.[5-9]\d*[ ]*(\|c(?:\|-?\d|)\}\})/gi, '$13$2');
	regex(/(\{INRConvert\|-?\d{2,})1\.[5-9]\d*[ ]*(\|c(?:\|-?\d|)\}\})/gi, '$12$2');
	regex(/(\{INRConvert\|-?\d{2,})0\.[5-9]\d*[ ]*(\|c(?:\|-?\d|)\}\})/gi, '$11$2');
	regex(/(\{INRConvert\|-?\d{3,})\.[0-4]\d*[ ]*(\|c(?:\|-?\d|)\}\})/gi, '$1$2');
 
	regex(/(\{INRConvert\|)(-?\d+)0000[ ]*\|l(\|-?\d|)(?:\|nolink=yes|)((?:\|year=\d4|)\}\})/gi, '$1$2|b$3$4');
	regex(/(\{INRConvert\|)(-?\d+)0[ ]*\|l(\|-?\d|)(?:\|nolink=yes|)((?:\|year=\d4|)\}\})/gi, '$1$2|m$3$4');
	regex(/(\{INRConvert\|)(-?\d+)(\d)[ ]*\|l(\|-?\d|)(?:\|nolink=yes|)((?:\|year=\d4|)\}\})/gi, '$1$2.$3|m$4$5');
	regex(/(\{INRConvert\|)(-?\d+)[ ]*\|l(\|-?\d|)(?:\|nolink=yes|)((?:\|year=\d4|)\}\})/gi, '$1$200000$3$4');
	regex(/(\{INRConvert\|)(-?\d+)\.(\d)[ ]*\|l(\|-?\d|)(?:\|nolink=yes|)((?:\|year=\d4|)\}\})/gi, '$1$2$30000$4$5');
	regex(/(\{INRConvert\|)(-?\d+)\.(\d)(\d)[ ]*\|l(\|-?\d|)(?:\|nolink=yes|)((?:\|year=\d4|)\}\})/gi, '$1$2$3$4000$5$6');
//	regex(/(\{INRConvert\|)(-?\d+)(\d)[ ]*\|l(\|-?\d|)(?:\|nolink=yes|)((?:\|year=\d4|)\}\})/gi, '$1$2.$3|m$4$5');
	regex(/(\{INRConvert\|)(-?\d+)\.(\d)[ ]*\|c(\|-?\d|)(?:\|nolink=yes|)((?:\|year=\d4|)\}\})/gi, '$1$2$3|m$4$5');
	regex(/(\{INRConvert\|)(-?\d+)\.(\d)(\d+)[ ]*\|c(\|-?\d|)(?:\|nolink=yes|)((?:\|year=\d4|)\}\})/gi, '$1$2$3.$4|m$5$6');
	regex(/(\{INRConvert\|)(-?\d+)00[ ]*\|c(\|-?\d|)(?:\|nolink=yes|)((?:\|year=\d4|)\}\})/gi, '$1$2|b$3$4');
	regex(/(\{INRConvert\|)(-?\d+)(\d)0[ ]*\|c(\|-?\d|)(?:\|nolink=yes|)((?:\|year=\d4|)\}\})/gi, '$1$2.$3|b$4$5');
	regex(/(\{INRConvert\|)(-?\d+)(\d\d)[ ]*\|c(\|-?\d|)(?:\|nolink=yes|)((?:\|year=\d4|)\}\})/gi, '$1$2.$3|b$4$5');
	regex(/(\{INRConvert\|)(-?\d+)[ ]*\|c(\|-?\d|)(?:\|nolink=yes|)((?:\|year=\d4|)\}\})/gi, '$1$20|m$3$4');
 
	regex(/(\{INRConvert\|-?\d{2,})8\.[5-9]\d*[ ]*(\|[bm](?:\|-?\d|)\}\})/gi, '$19$2');
	regex(/(\{INRConvert\|-?\d{2,})7\.[5-9]\d*[ ]*(\|[bm](?:\|-?\d|)\}\})/gi, '$18$2');
	regex(/(\{INRConvert\|-?\d{2,})6\.[5-9]\d*[ ]*(\|[bm](?:\|-?\d|)\}\})/gi, '$17$2');
	regex(/(\{INRConvert\|-?\d{2,})5\.[5-9]\d*[ ]*(\|[bm](?:\|-?\d|)\}\})/gi, '$16$2');
	regex(/(\{INRConvert\|-?\d{2,})4\.[5-9]\d*[ ]*(\|[bm](?:\|-?\d|)\}\})/gi, '$15$2');
	regex(/(\{INRConvert\|-?\d{2,})3\.[5-9]\d*[ ]*(\|[bm](?:\|-?\d|)\}\})/gi, '$14$2');
	regex(/(\{INRConvert\|-?\d{2,})2\.[5-9]\d*[ ]*(\|[bm](?:\|-?\d|)\}\})/gi, '$13$2');
	regex(/(\{INRConvert\|-?\d{2,})1\.[5-9]\d*[ ]*(\|[bm](?:\|-?\d|)\}\})/gi, '$12$2');
	regex(/(\{INRConvert\|-?\d{2,})0\.[5-9]\d*[ ]*(\|[bm](?:\|-?\d|)\}\})/gi, '$11$2');
	regex(/(\{INRConvert\|-?\d{3,})\.[0-4]\d*[ ]*(\|[bm](?:\|-?\d|)\}\})/gi, '$1$2');
 
	//Currency notation placements  [$£₤¥€]
	regex(/\s(\$(?:\d+\.\d\d?|\d{1,3}|\d{1,3},\d{3}))((?:\s|&nbsp;)(?:m|b|tr)illion|)[ ]*(?:US(?:[D$]|\s?dollars?))\b/gi, ' US$1$2');

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

	regex(/(\d)♭(\w| )/g, '$1$2');

//remove useless comments
	regex(/<!-- Metadata: see \[\[Wikipedia:Persondata\]\]\. -->/gi, '');

//Deleted image cleanup
	regex(/<!-- Deleted image removed:[^>]*? -->\n*/gi, '');

//	setoptions(minor='true');		//removed ",watch='false'" in response to user notification 13 Nov. 2010
//	setreason('remove bold formatting', 'append');
}

/** ------------------------------------------------------------------------ **/
/// PROTECTION BY STRING SUBSTITUTION
 
var linkmap=[];
function ohc_downcase_CEO()
{
    // protects categories, templates, link pipings, quotes, etc
    // the sensitive part is stored and replaced with a unique identifier,
    // which is later replaced with the stored part.
 
    var protect_function = function(s, begin, replace, end) {
        linkmap.push(replace);
        return begin + "⍌"+(linkmap.length-1)+"⍍" + end;
    };
    regex(/(<(?:imagemap)>)([\s\S]*)(<\/(?:imagemap)>)/gi, protect_function);
    regex(/(\{(?:Coord|See ?also|Main|Wikisource))(\|[^{}]*)(\})/gi, protect_function);
    regex(/((?:Category|File|Image):)([^|\]]*)([\|\]])/gi, protect_function);
    regex(/(\|\s*edition\s*=)([^|\]]*)([\|\]])/gi, protect_function);
    regex(/(\|\s*\w*\s*=\s*)(\d(?:st|nd|rd|th)[^|\]]*)([\|\]])/gi, protect_function);
    regex(/(\D)(\d(?:st|nd|rd|th)(?: (?:to |and )(?:the |)\d{1,2}(?:st|nd|rd|th)|) (?:centur|ed[i\. ]|grade|millenni[au]|parallel|round))(.)/gi, protect_function); //protecting lower case terms only; code does not expand where ordinal num is followed by a block cap
    regex(/((?:cover|file(?:name|)|image\d?|image_skyline|image[ _]location\d?|image[ _]name|img|pic|map|title|quote)\s*=)([^\|\}]*)([\|\}])/gi, protect_function);
    regex(/(\[(?:https?:|ftp:))([^\]]*)(\])/gi, protect_function);
    regex(/(\[\[\w*)([^\|\]]*)(\|)/gi, protect_function);
    regex(/(\{\{\w*)([^\|=\[\]]*)(\}\})/gi, protect_function);
    regex(/(<ref name=)([^<>]*)(>)/gi, protect_function);
    regex(/(\{Infobox)( non Test)( cricket)/gi, protect_function);
    regex(/(.)((?:Chairman's|President'?s) (?:XI|Cup))(.)/g, protect_function);
    regex(/(.)(100\scrore club)(.)/gi, protect_function);
    regex(/(.)(Conference of Presidents)(.)/g, protect_function);
 
        regex(/C(hief )E(xecutive )O(fficer\W)/g, 'c$1e$2o$3');
 //       regex(/C(hief )E(xecutive\W)/g, 'c$1e$2'); //too many false positives
        regex(/C(hief )F(inancial )O(fficer\W)/g, 'c$1f$2o$3');
        regex(/C(hief )O(perating )O(fficer\W)/g, 'c$1o$2o$3');
        regex(/C(hief )I(nformation )O(fficer\W)/g, 'c$1i$2o$3');
        regex(/C(hief )M(arketing )O(fficer\W)/g, 'c$1m$2o$3');
        regex(/M(anaging )D(irector\W)/g, 'm$1d$2');
        regex(/G(eneral )M(anager\b)(?!of|[ ]*=)/g, 'g$1m$2');
        regex(/B(oard (?:of |))D(irectors?\W)/g, 'b$1d$2');
        regex(/B(oard )M(embers?\W)/g, 'b$1m$2');
        regex(/C(ommittee )M(embers?\W)/g, 'c$1m$2');
        regex(/I(ndependent )D(irectors?\W)/g, 'i$1d$2');
        regex(/I(ndependent )N(on[\s\-])[Ee](xecutive )D(irectors?\W)/g, 'I$1n$2e$3d$4');
        regex(/N(on)[\s\-][Ee](xecutive )D(irectors?\W)/g, 'n$1-e$2d$3');
        regex(/C(hair(?:man|) of the )B(oard\W)/g, 'c$1b$2');
        regex(/(\w\s)V(ice)[\s\-]C(hair(?:man|)\W)(?!of)/g, '$1v$2-c$3');
        regex(/(\w\s)C(hairman\W)(?!of)/g, '$1c$2');
        regex(/C(ompany )S(ecretary\W)(?!of)/g, 'c$1s$2');
        regex(/G(eneral )S(ecretary\W)(?!of)/g, 'g$1s$2');
//        regex(/(\b[^A-Z]\w*[^neS]\.?\s)V(ice)[\s\-]P(resident\W|rincipal)(?!of)/g, '$1v$2-p$3');
        regex(/(\w\s+)P(residents)/g, '$1p$2');
//        regex(/(\b[^A-Z]\w*[^neS]\.?\s)P(resident\W)(?!of)/g, '$1p$2');
//        regex(/(\w\s)D(eputy) P(rime)[\s\-]M(inister\W)(?!of)/g, '$1d$2 p$3 m$4');
        regex(/([Aa]\s)M(ember of )P(arliament\W)/g, '$1m$2p$3');
        regex(/(\w\s)M(embers of )P(arliament\W)/g, '$1m$2p$3');

// Euros - replace space as separator
	regex(/(€|Euros?) ?(\d+)[\. ](\d{3})[\. ](\d{3})[\. ](\d{3})[\. ](\d{3})(?=\W)/g, '$1$2,$3,$4,$5,$6');
	regex(/(€|Euros?) ?(\d+)[\. ](\d{3})[\. ](\d{3})[\. ](\d{3})(?=\W)/g, '$1$2,$3,$4,$5');
	regex(/(€|Euros?) ?(\d+)[\. ](\d{3})[\. ](\d{3})(?=\W)/g, '$1$2,$3,$4');
	regex(/(€|Euros?) ?(\d{3})[\. ](\d{3})(?=\W)/g, '$1$2,$3');
	regex(/(\d+)[\. ](\d{3})[\. ](\d{3}) ?(€|Euros?|\[\[(?:€|Euros?\||)(?:€|Euros?)\]\])(?=\W)/g, '$4$1,$2,$3');
	regex(/(\d+)[\. ](\d{3}) ?(€|Euros?|\[\[(?:€|Euros?\||)(?:€|Euros?)\]\])(?=\W)/g, '$3$1,$2');

// replace full stop as thousands separator
	regex(/(\|[\s\']+)(\d+)[\. ](\d{3})[\. ](\d{3})[\. ](\d{3})(?=[ ']*[|\n<])/g, '$1$2,$3,$4,$5');
	regex(/(\|[\s\']+)(\d+)[\. ](\d{3})[\. ](\d{3})(?=[ ']*[|\n<])/g, '$1$2,$3,$4');
	regex(/(\|[\s\']+)(\d+)[\. ](\d{3})(?=[ ']*[|\n<])/g, '$1$2,$3');

// replace comma as decimal separator
	regex(/(\|[\s\']+)(\d+),(\d\d?)(?=[ ']*[|\n<])/g, '$1$2.$3');
	regex(/(\(\d+),(\d\d?%\))/g, '$1.$2');	//percentages in parentheses
	regex(/(\{\{(?:de|in)crease\}\}\s*)(\d+),(\d\d?)(?=[ ]*[|\n<])/g, '$1$2.$3');

	regex(/([€])[ ]*(\d+)(?=\W)/g, '$1$2');
	regex(/([€])(\d+),(\d\d?)(?=\W)/g, '$1$2.$3');
	regex(/(\W)(\d+),(\d\d?)[ ]*(?=[€%]|Euro?)/g, '$1$2.$3');
	regex(/(\|\s*attendance\s*=\s*\d{1,3})[\.]?(\d{3}\D)/gi, '$1,$2');

// layout - rem horizontal lines per WP:LAYOUT
//	regex(/(\n)----\n/g, '$1'); // html element - may sometimes be appropriate – disabled per discussion at WT:LAYOUT July 2014

//remove Crores and Lakhs not in templates
	regex(/(\d+)[ ]?(?:lakh|\[\[lakh\]\])[\- ](?:crores?|\[\[crores?\]\])/g, '$1&nbsp;trillion ([[Long and short scales|short scale]])');

    regex(/(?:(\d+),|)(\d+)0,000(?:&nbsp;|\s)?(?:[Ll]acs?|[Ll]akhs?|\[\[[Ll]akhs?(?:\|[Ll]|\|[Ll]acs?|\|[Ll]akhs?|)\]\]s?)(?=[^\-\w])/g, '$1$2&nbsp;billion');
	regex(/(?:(\d+),|)(\d+)\.(\d)(?:&nbsp;|\s)?(?:[Ll]acs?|[Ll]akhs?|\[\[[Ll]akhs?(?:\|[Ll]|\|[Ll]acs?|\|[Ll]akhs?|)\]\]s?)(?=[^\-\w])/g, '$1$2$30,000');
	regex(/(?:(\d+),|)(\d+)\.(\d)(\d)(?:&nbsp;|\s)?(?:[Ll]acs?|[Ll]akhs?|\[\[[Ll]akhs?(?:\|[Ll]|\|[Ll]acs?|\|[Ll]akhs?|)\]\]s?)(?=[^\-\w])/g, '$1$2$3$4,000');
	regex(/(?:(\d+),|)(\d+)0(?:&nbsp;|\s)?(?:[Ll]acs?|[Ll]akhs?|\[\[[Ll]akhs?(?:\|[Ll]|\|[Ll]acs?|\|[Ll]akhs?|)\]\]s?)(?=[^\-\w])/g, '$1$2&nbsp;million');
	regex(/(?:(\d+),|)(\d+)(\d+)(?:&nbsp;|\s)?(?:[Ll]acs?|[Ll]akhs?|\[\[[Ll]akhs?(?:\|[Ll]|\|[Ll]acs?|\|[Ll]akhs?|)\]\]s?)(?=[^\-\w])/g, '$1$2.$3&nbsp;million');
	regex(/(?:(\d+),|)(\d+)(?:&nbsp;|\s)?(?:[Ll]acs?|[Ll]akhs?|\[\[[Ll]akhs?(?:\|[Ll]|\|[Ll]acs?|\|[Ll]akhs?|)\]\]s?)(?=[^\-\w])/g, '$1$200,000');
	regex(/(?:(\d+),|)(\d+)\.(\d)(?:&nbsp;|\s)?(?:[Cc]rs?|[Cc]rores?|\[\[[Cc]rores?(?:\|[Cc]rs?|\|[Cc]rores?|)\]\]s?)(?=[^\-\w])/g, '$1$2$3&nbsp;million');
	regex(/(?:(\d+),|)(\d+)\.(\d)(\d+)(?:&nbsp;|\s)?(?:[Cc]rs?|[Cc]rores?|\[\[[Cc]rores?(?:\|[Cc]rs?|\|[Cc]rores?|)\]\]s?)(?=[^\-\w])/g, '$1$2$3.$4&nbsp;million');
	regex(/(?:(\d+),|)(\d+)00(?:&nbsp;|\s)?(?:[Cc]rs?|[Cc]rores?|\[\[[Cc]rores?(?:\|[Cc]rs?|\|[Cc]rores?|)\]\]s?)(?=[^\-\w])/g, '$1$2&nbsp;billion');
	regex(/(?:(\d+),|)(\d+)(\d\d)(?:&nbsp;|\s)?(?:[Cc]rs?|[Cc]rores?|\[\[[Cc]rores?(?:\|[Cc]rs?|\|[Cc]rores?|)\]\]s?)(?=[^\-\w])/g, '$1$2.$3&nbsp;billion');
	regex(/(?:(\d+),|)(\d+)(?:&nbsp;|\s)?(?:[Cc]rs?|[Cc]rores?|\[\[[Cc]rores?(?:\|[Cc]rs?|\|[Cc]rores?|)\]\]s?)(?=[^\-\w])/g, '$1$20&nbsp;million');

// Indian commas
	regex(/(\W)(\d{1,3}),(\d\d),(\d\d),(\d\d),(\d\d),(\d\d\d)(?=[\s\.,–]\D)/g, '$1{{formatnum:$2$3$4$5$6$7}}');
	regex(/(\W)(\d{1,3}),(\d\d),(\d\d),(\d\d),(\d\d\d)(?=[\s\.,–]\D)/g, '$1{{formatnum:$2$3$4$5$6}}');
	regex(/(\W)(\d{1,3}),(\d\d),(\d\d),(\d\d\d)(?=[\s\.,–]\D)/g, '$1{{formatnum:$2$3$4$5}}');
	regex(/(\W)(\d{1,3}),(\d\d),(\d\d\d)(?=[\s\.,–]\D)/g, '$1{{formatnum:$2$3$4}}');

	regex(/(\{INR)\}\}[ ]*\{\{formatnum:(\d+\}\})/g, '$1Convert|$2');
//	regex(/(\{\{(?:INR|Indian Rupee)\}\}|Rs\.?) (\d+)/g, '$1$2');

    //removes protection put in place by function ohc_protect_fmt (all cats, templates etc.)
    regex(/⍌([0-9]+)⍍/g, function(x, n) {
        var res = linkmap[n];
        res = res.replace(/⍌([0-9]+)⍍/g, function(x, n) {
            var res = linkmap[n];
            res = res.replace(/⍌([0-9]+)⍍/g, function(x, n) {
                var res = linkmap[n];
                res = res.replace(/⍌([0-9]+)⍍/g, function(x, n) {
                    return linkmap[n];
                });
                return res;
            });
            return res;
        });
        return res;
    });
}
 
/** ------------------------------------------------------------------------ **/
/// LINKSPAM removal with protection for Reference tags and External links

var linkmap=[];
function ohc_linkspam()
{
    // protects everything within reference tags 
    // the sensitive part is stored and replaced with a unique identifier,
    // which is later replaced with the stored part.
 
    var protect_function = function(s, begin, replace, end) {
        linkmap.push(replace);
        return begin + "⍌"+(linkmap.length-1)+"⍍" + end;
    };

    regex(/(== ?(?:Bibliography|Further reading|Sources|Works) ?==+)(\n[\S\s]*?)(\n)(?===)/gi, protect_function);
    regex(/(== ?External links ?==)(\n[\S\s]*?)(\[\[Category:[^\]]+\]\])/gi, protect_function);
    regex(/({{refn\|)([^}]*?)(}})/gi, protect_function);
    regex(/(<ref name="[^\"]*?" ?>)([\s\S]*?)(<\/ref>)/gi, protect_function);
    regex(/(<ref[^/>]*?>)([\s\S]*?)(<\/ref>)/gi, protect_function);
    regex(/([=\*][ ]?\[(?:https?:|ftp:))([^\]]*)(\])/gi, protect_function);


 
	regex(/([^>\*][ ]?)\[https?:\/\/[^\s\[\]]*[ ]+([\'\"\w][^\[\]]*)\](?![ ]*[\n\-]+)/gi, '$1$2');



    //removes protection put in place by function ohc_protect_fmt (all cats, templates etc.)
    regex(/⍌([0-9]+)⍍/g, function(x, n) {
        var res = linkmap[n];
        res = res.replace(/⍌([0-9]+)⍍/g, function(x, n) {
            var res = linkmap[n];
            res = res.replace(/⍌([0-9]+)⍍/g, function(x, n) {
                var res = linkmap[n];
                res = res.replace(/⍌([0-9]+)⍍/g, function(x, n) {
                    return linkmap[n];
                });
                return res;
            });
            return res;
        });
        return res;
    });
}

function ohc_change_type(){

//update syntax of 'File'
//	regex(/\[\[(file|[Ii]mage):/g, '[[File:');
//add {{url}} template to infobox parameter
	regex(/({{) ?(url) ?(?=\|)/gi, '$1$2');
	regex(/({{url\|)[ ]*https?:\/\/(?:www\.|)([^\}]+}})[ ]*(?=[\n\r])/gi, '$1$2');
	regex(/(homepage[ ]*=)[ ]*https?:\/\/(?:www\.|)([^\s\[\]]+)(?=[\s])/gi, '$1{{url|$2}}');
	regex(/((?:homepage|website)[ ]*=)[ ]*\[https?:\/\/(?:www\.|)([^\s\[\]]+) official (?:web|)site\](?=[\s])/gi, '$1{{url|$2}}');
	regex(/({{url\|)([^\}]+)\|\2}}(?=[\s])/gi, '$1$2}}');

//remove icons from headers (needs to occur before protection)
	regex(/(==[ ]?(?:[^\[\n=]*))\[\[(?:File|image):[^\]]+?\]\]([^\[=\n]*)([ ]?==)/gi, '$1$2$3');


}

function Ohc_final_cleanup(){

//adjust piping - remove redundant, adding piping for parentheticals
         regex(/\[\[([^\]\|]*)\|\1([^-\] ]*|)(\]\])/gi, '[[$1$3$2');
         regex(/\[\[([^\[\]\(\)\|:]*)( \((?:\d{4} |)film\))(\]\])/gi, '\'\'[[$1$2|$1$3\'\'');
         regex(/\[\[([^\[\]\(\)\|:]*)( \([^\[\]\(\)\|]*\))(\]\])(?![\s\n])/gi, '[[$1$2|$1$3');

// deprecated parameters in citation templates
	regex(/(\|\s*)coauthors(\s*=\s*)/g, '$1author2$2');

}

function Ohc_downcase_headings(){
//cleanup of headings per MOSHEAD before complete downcasing (most code is copied from other parts of the script)
// remove file 
	regex(/(==[ ]?(?:[^\[\n=]*))\[\[(?:File|image):[^\]]+?\]\]([^\[=\n]*)([ ]?==)/gi, '$1$2$3');

//rem linking within section headings
	regex(/(==[ ]?(?:[^\[\n=]*))\[\[([^\|\]]+?)\]\]((?:[^\[=\n]*|)[ ]?==)/gi, '$1$2$3');
	regex(/(==[ ]?(?:[^\[\n=]*))\[\[[^\|\]]+?\|([^\]]+?)\]\]((?:[^\[=\n]*|)[ ]?==)/gi, '$1$2$3');
	regex(/(==[ ]?(?:[^\[\n=]*))\[\[(?:[^\|\]]+?\||)([^\]]+?)\]\]([^\[\|]*)\[\[(?:[^\|\]]+?\||)([^\]]+?)\]\](?:([^\[\|]*)\[\[(?:[^\|\]]+?\||)([^\]]+?)\]\]|)((?:[^\[=\n]*|)[ ]?==)/gi, '$1$2$3$4$5$6$7');

//rem refs within section headings
	regex(/(==[ ]?(?:[^<>\n]*))(?:<ref(?:>[^<>]*<\/ref| name=[^\/>]+\/)>)([^<>\n]*)(?=[ ]?==)/gi, '$1$2');

//original code
	regex(/(==+[ ]?[A-Z])([^\[=|]*)(?===+ ?\n)/g, '$1{{' + 'subst:' + 'lc:$2}}');

}
 
function Ohc_castlist(){
    //remove flagicons from country, birth and death
	regex(/(\* )(\[\[[-\w' ]*\]\]) as ([^,\.]*)([,.])([^\n<]*)([\n<])/gi, '$1\'\'\'$3\'\'\' ($2)$4$5$6');

}
 
/** ------------------------------------------------------------------------ **/
/// PROTECTION BY STRING SUBSTITUTION
 
var linkmap=[];
function ohc_protect_fmt()
{
    // protects categories, templates, link pipings, quotes, etc
    // the sensitive part is stored and replaced with a unique identifier,
    // which is later replaced with the stored part.
 
    var protect_function = function(s, begin, replace, end) {
        linkmap.push(replace);
        return begin + "⍌"+(linkmap.length-1)+"⍍" + end;
    };
    regex(/(\{Wikisource\|)([\}]*)(\})/gi, protect_function);
    regex(/((?:Category|File|Image):)([^|\]]*)([\|\]])/gi, protect_function);
    regex(/((?:[a-z]{2,3}):)([^|\]]*)([\|\]])/gi, protect_function);
    regex(/(\{(?:See ?also|Main))(\|[^{}]*)(\})/gi, protect_function);
    regex(/((?:cover|file(?:name|)|image\d?|image_skyline|image[ _]location\d?|image[ _]name|img|pic|map)\s*=)([^\|\}]*)([\|\}])/gi, protect_function);
    regex(/(\[\[\w*)([^\|\]]*)(\|)/gi, protect_function);
    regex(/(\{\{\w*)([^\|=\[\]]*)(\}\})/gi, protect_function);
    regex(/(<ref name=)([^<>]*)(>)/gi, protect_function);
    regex(/(\{Infobox)( non Test)( cricket)/gi, protect_function);
    regex(/(\d[]*)(Cr App R)(.)/g, protect_function);
    regex(/(.)(On a Friday)(.)/g, protect_function);
    regex(/(.)(Octopussy and the living daylights)(.)/gi, protect_function);
    regex(/(.)(\'?Carry On [A-Z][a-z]*)(.)/g, protect_function);
    regex(/(.)(10 metre (?:air|running) \w*)(.)/g, protect_function);
    regex(/(.)(\d day (?:schools) \w*)(.)/g, protect_function);
 
}


function ohc_unprotect_fmt()
{
    //removes protection put in place by function ohc_protect_fmt (all cats, templates etc.)
    regex(/⍌([0-9]+)⍍/g, function(x, n) {
        var res = linkmap[n];
        res = res.replace(/⍌([0-9]+)⍍/g, function(x, n) {
            var res = linkmap[n];
            res = res.replace(/⍌([0-9]+)⍍/g, function(x, n) {
                var res = linkmap[n];
                res = res.replace(/⍌([0-9]+)⍍/g, function(x, n) {
                    return linkmap[n];
                });
                return res;
            });
            return res;
        });
        return res;
    });
}

/** ------------------------------------------------------------------------ **/
 
function Ohc_formats(){
//driver

	Ohc_format_Sundry();
	Ohc_format_MOSCAPS();
	Ohc_format_MOSFLAG();
	Ohc_format_MOSPUNCT();
	Ohc_format_MOSHASH();
	Ohc_format_COMMONALITY();
}

function Ohc_formatgeneral() {
	ohc_change_type();
	ohc_protect_fmt();
	Ohc_formats();
	ohc_unprotect_fmt();
	ohc_downcase_CEO();
	ohc_linkspam();
	Ohc_final_cleanup();
	
}

function Ohc_run_formatgeneral() {
	Ohc_formatgeneral();
	Ohc_formatgen_edit_summary();

}

function Ohc_formatgen_edit_summary(){
	//Add a tag to the summary box
	setoptions(minor='true'); 		
	setreason('General [[WP:MOS|formatting]] by [[User:Ohconfucius/script|script]]', 'append');
	doaction('diff');
}
$(function () {
 if(document.forms.editform) {
  mw.util.addPortletLink('p-tb', 'javascript:Ohc_run_formatgeneral()', 'General formatting', 't-addmetric', 'Fixes some unit formatting', '', '');

  }
});