User:Frietjes/fb.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:Frietjes/fb. |
// <nowiki>
jQuery(document).ready(function($) {
var myContent = document.getElementsByName('wpTextbox1')[0];
// -------------------------------------------------------------------------------- //
mysummary = "expand templates per [[Wikipedia:Templates_for_discussion/Log/2018_April_20#Mass_Fb_team_templates|Fb team TfD outcome]] and [[Wikipedia:Templates_for_discussion/Log/2018_April_27#Mass_Fb_competition_templates|Fb competition TfD outcome]] and [[Wikipedia:Templates_for_discussion/Log/2018_April_19#Mass_Fb_cl_templates|Fb cl TfD outcome]]" + " and [[Wikipedia:Templates_for_discussion/Log/2018_September_4#Fb_rbr_templates|Fb rbr TfD outcome]]";
mysummary = "update template syntax";
if(typeof fbeditsummary == 'string') {mysummary = fbeditsummary;}
if(typeof findargdupseditsummary == 'string') {mysummary = findargdupseditsummary;}
var linktext = "Convert fb";
// -------------------------------------------------------------------------------- //
if(mw.config.get('wgNamespaceNumber') != -1 && myContent && (mw.config.get('wgUserName') == 'Hhkohh' || mw.config.get('wgUserName') == 'Jolicnikola' || mw.config.get('wgUserName') == 'Frietjes')) {
mw.loader.using(['mediawiki.util']).done( function() {
var portletlink = mw.util.addPortletLink('p-tb', '#', linktext, 't-ffb');
$(portletlink).click(function(e) {
e.preventDefault();
wpFb();
});
});
}
// -------------------------------------------------------------------------------- //
function myPrompt(s, d, b) {
var r = prompt(s,d);
if (r === null) {
alert('Null is not valid!');
return myPrompt(s, d, b);
} else if ((r == '') && (b == false)) {
alert('Blank is not valid!');
return myPrompt(s, d, r);
} else {
return r;
}
}
// -------------------------------------------------------------------------------- //
function wpFbr2(s,f)
{
var lt = '';
while(lt != s) {
lt = s;
s = s.replace(/(\{\{)[_ ]*[Ff]b[_ ]+r2?[_ ]+(header|team)[_ ]*/g, '$1fb r2 $2');
s = s.replace(/(\{\{)[_ ]*[Ff]b[_ ]+r2?[_ ]*(\||\}\})/g, '$1fb r$2');
s = s.replace(/(\{\{fb r(?:2 header|2 team)(?:\{\{[^{}]*\}\}|[^{}])*)[\s][\s]*(\||=|\}\}|\])/g, '$1$2');
s = s.replace(/(\{\{fb r(?:2 header|2 team)(?:\{\{[^{}]*\}\}|[^{}])*[\|=\[])[\s][\s]*/g, '$1');
s = s.replace(/(\{\{fb r(?:2 header|2 team)(?:\{\{[^{}]*\}\}|[^{}])*)\{\{nowrap\|([^{}]*)\}\}/gi, '$1$2');
s = s.replace(/(\{\{fb r(?:2 header|2 team)(?:\{\{[^{}]*\}\}|[^{}])*) /gi, '$1 ');
s = s.replace(/(\{\{fb r(?:2 header|2 team)(?:\{\{[^{}]*\}\}|[^{}])*)\{\{0\}\}/gi, '$1 ');
s = s.replace(/(\{\{fb r(?:2 header|2 team)(?:\{\{[^{}]*\}\}|[^{}])*)<[\/ ]*br[\/ ]*>/gi, '$1 ');
s = s.replace(/(\{\{fb r(?:\{\{[^{}]*\}\}|[^{}])*)[\s]*\|[\s]*bg[\s]*=[\s]*[a-z]*[\s]*(\||\}\})/g, '$1$2');
s = s.replace(/(\{\{fb r(?:\{\{[^{}]*\}\}|[^{}])*)(\}\})[\s]*<sup>([^<>]*)<\/sup>/gi, '$1|nt=$3$2');
s = s.replace(/(\{\{fb r(?:\{\{[^{}]*\}\}|[^{}])*)(\}\})[\s]*\{\{ref\|([^<>]*)\|\3\}\}/gi, '$1|nt=$3$2');
s = s.replace(/(\{\{fb r(?:\{\{[^{}]*\}\}|[^{}])*)(\}\})[\s]*\{\{ref\|([^\{\}\|]*)\|([^\{\}\|]*)\}\}/gi, '$1|nt=$3?$4$2');
s = s.replace(/(\{\{fb r(?:\{\{[^{}]*\}\}|[^{}])*)(\}\})[\s]*\{\{ref[_ ]*label[_ ]*\|([^\{\}\|]*)\|([^\{\}\|]*)\|([^\{\}\|]*)\}\}/gi, '$1|nt=$3?$4?$5$2');
s = s.replace(/(\{\{fb r(?:\{\{[^{}]*\}\}|[^{}])*)[\s]*(\|[\s]*nt[\s]*=[\s]*(?:\{\{[^{}]*\}\}|[^\[\]\{\}\|])*)[\s]*(\|[\s]*ma[\s]*=[\s]*[^\[\]\{\}\|]*)(\||\}\})/g, '$1$3$2$4');
s = s.replace(/(\{\{fb r\|(?:\{\{[^{}]*\}\}|[^{}])*)[\s]+(\||\}\}|=)/g, '$1$2');
s = s.replace(/(\{\{fb r\|(?:\{\{[^{}]*\}\}|[^{}])*)(\|ot=y)([^{}]*)(\}\})/g, '$1$3$2$4');
}
var oldtext = s;
if(s.search(/(\{\{fb r2 header[\s]*(?:\{\{[^{}]*\}\}|[^{}])*\}\})/g) < 0) {
return oldtext;
}
var hdr = (s.match(/(\{\{fb r2 header[\s]*(?:\{\{[^{}]*\}\}|[^{}])*\}\})/g))[0];
hdr = hdr.replace(/\{\{fb r2 header[\s]*((?:\{\{[^{}]*\}\}|[^{}])*)\}\}/g, '$1');
var teamnum = 0;
if(hdr.search(/\|[ ]*nt[ ]*=[0-9 ]*/g) >= 0) {
teamnum = (hdr.match(/\|[ ]*nt[ ]*=[0-9 ]*/g))[0];
teamnum = teamnum.replace(/\|[ ]*nt[ ]*=[ ]*/, '');
if (teamnum.search(/[0-9]/) >= 0) {
teamnum = teamnum.replace(/[^0-9]/g, '');
teamnum = Number(teamnum);
} else {
teamnum = 0;
}
}
hdr = hdr.replace(/\|[ ]*nt[ ]*=[0-9 ]*/g, '');
hdr = hdr.replace(/(\[\[[^\[\]]*)\|/g, '$1{'+'{!}'+'}');
hdr = hdr.replace(/(\{\{[_ ]*[Ff]lagicon[_ ]*)\|/g, '$1_THIS_IS_A_PIPE_');
hdr = hdr.replace(/(\{\{[_ ]*[Ff]lagicon[^{}\|]*)\|/g, '$1_THIS_IS_A_PIPE_');
hdr = hdr.replace(/^[\s]*\|[\s]*/, '');
var teams = hdr.split(/[\s]*\|[\s]*/g);
if (teamnum === 0) {
return oldtext;
} else if (teamnum != teams.length) {
alert('Found nt = ' + teamnum + ' which does not match the number of listed teams (' + teams.length + ') ' + teams.join('; '));
return oldtext;
}
hdr = '{' + '{#invoke:sports results|main\n|matches_style=FBR|solid_cell=grey\n';
var teamlinks = new Array(teams.length);
for (i=0; i<teams.length; i++) {
var a = teams[i];
a = a.replace(/^[\s]*/, '');
a = a.replace(/[\s]*$/, '');
if( a.search(/^[\s]*\[\[.*\{\{!\}\}([^\[\]]*)\]\].*$/) >=0) {
teamlinks[i] = a.replace(/^[\s]*\[\[(.*)\{\{!\}\}([^\[\]]*)\]\].*$/g, '$1');
a = a.replace(/^[\s]*\[\[(.*)\{\{!\}\}([^\[\]]*)\]\].*$/g, '$2');
} else {
a = a.replace(/\[\[([^\[\]]*)\]\].*$/g, '$1');
teamlinks[i] = a;
a = a.replace(/\{\{[_ ]*[Ff]lagicon[_ ]*_THIS_IS_A_PIPE_([^{}]*)\}\}/g, '$1');
a = a.replace(/[\s\-\.]/g, '');
a = a.replace(/^[\s]*([^\s][^\s][^\s][^\s]).*$/, '$1');
//a = a.toUpperCase();
}
var re = new RegExp('\\|team[0-9]+=' + a + '\\n', 'g');
if (hdr.search(re) >= 0) {
alert('Changing "' + a + '" to "' + (a + (i+1) ) + '" due to abbreviation collision');
a = a + (i+1);
}
hdr = hdr + '|team' + (i+1) + '=' + a + '\n';
teams[i] = a;
}
s = s.replace(/\{\{fb r2 header[\s]*(?:\{\{[^{}]*\}\}|[^{}])*\}\}/g, hdr + '<!-- FB R2 ROW1 -->');
for(i=0; i<teams.length; i++) {
s = s.replace(/(<!-- FB R2[^<>]*-->)[\s]*/g, '\n$1');
s = s.replace(/(<!-- FB R2[^<>]*-->)\|\-[^\r\n]*/g, '$1');
s = s.replace(/(<!-- FB R2[^<>]*-->)[\s]*/g, '$1');
s = s.replace(/(<!-- FB R2[^<>]*-->)(!|\|)[ ]*style[\s]*=[\s"]*text\-align[\s]*:[\s]*right[;\s"]*\|/g, '$1$2');
s = s.replace(/(<!-- FB R2[^<>]*-->)[\t ]*\|[ ]*(\[\[)/g, '$1!$2');
var rt = new RegExp('<!-- FB R2 ROW' + (i+1) + ' -->\\{\\{fb r2 team[\\s]*\\|[\\s]*t[\\s]*=[\\s]*((?:\\{\\{[^{}]*\\}\\}|[^{}])*)\\}\\}', 'g');
s = s.replace(rt, '\n|name_' + teams[i] + '=<!--FB LINK: ' + teamlinks[i] +'-->$1\n<!-- FB R2 T' + (i+1) + ' RES1 -->');
rt = new RegExp('<!-- FB R2 ROW' + (i+1) + ' -->!((?:\\{\\{[^{}]*\\}\\}|[^{}\\r\\n])*)[\\r\\n]', 'g');
s = s.replace(rt, '\n|name_' + teams[i] + '=<!--FB LINK: ' + teamlinks[i] +'-->$1\n<!-- FB R2 T' + (i+1) + ' RES1 -->');
rt = new RegExp('<!-- FB R2 ROW' + (i+1) + ' -->\\|[\^\|]*\\|[\\s]*([^0-9\\|\\r\\n](?:\\{\\{[^{}]*\\}\\}|[^{}\\r\\n])*)[\\r\\n]', 'g');
s = s.replace(rt, '\n|name_' + teams[i] + '=<!--FBs LINK: ' + teamlinks[i] +'-->$1\n<!-- FB R2 T' + (i+1) + ' RES1 -->');
s = s.replace(/(\|name_[^=]*=)[\s]*style[\s]*=[^\|]*\|[\s]*/g, '$1');
s = s.replace(/<!--FB LINK: ([^<>]*)-->(\[\[)\1(\||\]\])/g, '$2$1$3');
s = s.replace(/_THIS_IS_A_PIPE_/g, '|');
s = s.replace(/<!--FB LINK: \{\{flagicon\|([^<>\|\{\}]*)(?:\||\}\})[^<>]*-->(\{\{fb[^{}\|]*\|)\1(\||\}\})/g, '$2$1$3');
s = s.replace(/<!--FB LINK: \{\{flagicon\|[^<>\|\{\}]*\|([^<>\|\{\}]*)(?:\||\}\})[^<>]*-->(\{\{fb[^{}\|]*\|)\1(\||\}\})/g, '$2$1$3');
for(j=0; j<teams.length; j++) {
s = s.replace(/(<!-- FB R2 T[0-9]+ RES[0-9]+ -->)(?:<!--[^<>]*-->|[\s])*/g, '$1');
s = s.replace(/(<!-- FB R2 T[0-9]+ RES[0-9]+ -->[\s\|]*)'''XXX['\s]*/g, '$1');
s = s.replace(/(<!-- FB R2 T[0-9]+ RES[0-9]+ -->[\s\|]*)(?:style|bgcolor)[^\|]*\|/g, '$1');
var rp;
if(j == i) {
rp = new RegExp('<!-- FB R2 T' + (i+1) + ' RES' + (j+1) + ' -->\\{\\{fb r\\|[\\s]*r[\\s]*=[\\s]*null[\\s]*\\}\\}', 'g');
s = s.replace(rp, '<!-- FB R2 T' + (i+1) + ' RES' + (j+2) + ' -->');
rp = new RegExp('<!-- FB R2 T' + (i+1) + ' RES' + (j+1) + ' -->(?:\\||!)[^\\|\\r\\n]*\\|[\\s]*\\|\\|*', 'g');
s = s.replace(rp, '<!-- FB R2 T' + (i+1) + ' RES' + (j+2) + ' -->|');
rp = new RegExp('<!-- FB R2 T' + (i+1) + ' RES' + (j+1) + ' -->(?:\\|)[\\s]*\\|\\|*', 'g');
s = s.replace(rp, '<!-- FB R2 T' + (i+1) + ' RES' + (j+2) + ' -->|');
rp = new RegExp('<!-- FB R2 T' + (i+1) + ' RES' + (j+1) + ' -->(?:\\||!)[\\s\|]*–[\t ]*[\r\n]', 'g');
s = s.replace(rp, '<!-- FB R2 T' + (i+1) + ' RES' + (j+2) + ' -->\n');
} else {
s = s.replace(/(<!-- FB R2 T[^<>]*-->)[\|\s]*style[\s]*=[\s]*[^\|]*/g, '$1');
rp = new RegExp('<!-- FB R2 T' + (i+1) + ' RES' + (j+1) + ' -->\\{\\{fb r\\|[\\s]*r[\\s]*=[\\s]*null[\\s]*\\}\\}', 'g');
s = s.replace(rp, '|match_' + teams[i] + '_' + teams[j] + '=null\n<!-- FB R2 T' + (i+1) + ' RES' + (j+2) + ' -->');
rp = new RegExp('<!-- FB R2 T' + (i+1) + ' RES' + (j+1) + ' -->\\{\\{fb r\\|[\\s]*r[\\s]*=[\\s]*\\}\\}', 'g');
s = s.replace(rp, '|match_' + teams[i] + '_' + teams[j] + '= \n<!-- FB R2 T' + (i+1) + ' RES' + (j+2) + ' -->');
rp = new RegExp('<!-- FB R2 T' + (i+1) + ' RES' + (j+1) + ' -->\\{\\{fb r\\|[\\s]*gf[\\s]*=[\\s]*\\|[\\s]*ga[\\s]*=[\\s]*\\}\\}', 'g');
s = s.replace(rp, '|match_' + teams[i] + '_' + teams[j] + '= \n<!-- FB R2 T' + (i+1) + ' RES' + (j+2) + ' -->');
rp = new RegExp('<!-- FB R2 T' + (i+1) + ' RES' + (j+1) + ' -->\\{\\{fb r[\\s]*\\}\\}', 'g');
s = s.replace(rp, '|match_' + teams[i] + '_' + teams[j] + '= \n<!-- FB R2 T' + (i+1) + ' RES' + (j+2) + ' -->');
rp = new RegExp('<!-- FB R2 T' + (i+1) + ' RES' + (j+1) + ' -->\\{\\{fb r\\|[\\s]*gf[\\s]*=[\\s]*([^\\{\\}\\|]*)[\\s]*\\|[\\s]*ga[\\s]*=[\\s]*([^\\{\\}\\|]*)[\\s]*\\|[\\s]*r[\\s]*=[\\s]*((?:\\{\\{[^{}]*\\}\\}|[^\\{\\}\\|])*)\\}\\}', 'g');
s = s.replace(rp, '|match_' + teams[i] + '_' + teams[j] + '=$1–$2<sup>$3</sup>|result_' + teams[i] + '_' + teams[j] + '=$3\n<!-- FB R2 T' + (i+1) + ' RES' + (j+2) + ' -->');
rp = new RegExp('<!-- FB R2 T' + (i+1) + ' RES' + (j+1) + ' -->\\{\\{fb r\\|[\\s]*gf[\\s]*=[\\s]*([^\\{\\}\\|]*)[\\s]*\\|[\\s]*ga[\\s]*=[\\s]*([^\\{\\}\\|]*)[\\s]*\\|[\\s]*ot[\\s]*=[\\s]*[Yy][a-z]*[\\s]*\\}\\}', 'g');
s = s.replace(rp, '|match_' + teams[i] + '_' + teams[j] + '=$1–$2|result_' + teams[i] + '_' + teams[j] + '=OT\n<!-- FB R2 T' + (i+1) + ' RES' + (j+2) + ' -->');
rp = new RegExp('<!-- FB R2 T' + (i+1) + ' RES' + (j+1) + ' -->\\{\\{fb r\\|[\\s]*gf[\\s]*=[\\s]*([^\\{\\}\\|]*)[\\s]*\\|[\\s]*ga[\\s]*=[\\s]*([^\\{\\}\\|]*)[\\s]*\\|[\\s]*f[\\s]*=[\\s]*[Yy][a-z]*[\\s]*\\}\\}', 'g');
s = s.replace(rp, '|match_' + teams[i] + '_' + teams[j] + '=$1–$2|result_' + teams[i] + '_' + teams[j] + '=F\n<!-- FB R2 T' + (i+1) + ' RES' + (j+2) + ' -->');
rp = new RegExp('<!-- FB R2 T' + (i+1) + ' RES' + (j+1) + ' -->\\{\\{fb r\\|[\\s]*gf[\\s]*=[\\s]*([^\\{\\}\\|]*)[\\s]*\\|[\\s]*ga[\\s]*=[\\s]*([^\\{\\}\\|]*)[\\s]*\\|[\\s]*ma[\\s]*=[\\s]*([^\\{\\}\\|]*)\\|[\\s]*ot[\\s]*=[\\s]*[Yy][a-z]*[\\s]*\\}\\}', 'g');
s = s.replace(rp, '|match_' + teams[i] + '_' + teams[j] + '=[[$3|$1–$2]]|result_' + teams[i] + '_' + teams[j] + '=OT\n<!-- FB R2 T' + (i+1) + ' RES' + (j+2) + ' -->');
rp = new RegExp('<!-- FB R2 T' + (i+1) + ' RES' + (j+1) + ' -->\\{\\{fb r\\|[\\s]*gf[\\s]*=[\\s]*([^\\{\\}\\|]*)[\\s]*\\|[\\s]*ga[\\s]*=[\\s]*([^\\{\\}\\|]*)[\\s]*\\|[\\s]*ma[\\s]*=[\\s]*([^\\{\\}\\|]*)\\|[\\s]*f[\\s]*=[\\s]*[Yy][a-z]*[\\s]*\\}\\}', 'g');
s = s.replace(rp, '|match_' + teams[i] + '_' + teams[j] + '=[[$3|$1–$2]]|result_' + teams[i] + '_' + teams[j] + '=F\n<!-- FB R2 T' + (i+1) + ' RES' + (j+2) + ' -->');
rp = new RegExp('<!-- FB R2 T' + (i+1) + ' RES' + (j+1) + ' -->\\{\\{fb r\\|[\\s]*gf[\\s]*=[\\s]*([^\\{\\}\\|]*)[\\s]*\\|[\\s]*ga[\\s]*=[\\s]*([^\\{\\}\\|]*)[\\s]*\\|[\\s]*nt[\\s]*=[\\s]*((?:\\{\\{[^{}]*\\}\\}|[^\\{\\}\\|])*)\\}\\}', 'g');
s = s.replace(rp, '|match_' + teams[i] + '_' + teams[j] + '=$1–$2\n|match_' + teams[i] + '_' + teams[j] + '_note=$3\n<!-- FB R2 T' + (i+1) + ' RES' + (j+2) + ' -->');
rp = new RegExp('<!-- FB R2 T' + (i+1) + ' RES' + (j+1) + ' -->\\{\\{fb r\\|[\\s]*gf[\\s]*=[\\s]*([^\\{\\}\\|]*)[\\s]*\\|[\\s]*ga[\\s]*=[\\s]*([^\\{\\}\\|]*)\\}\\}', 'g');
s = s.replace(rp, '|match_' + teams[i] + '_' + teams[j] + '=$1–$2\n<!-- FB R2 T' + (i+1) + ' RES' + (j+2) + ' -->');
rp = new RegExp('<!-- FB R2 T' + (i+1) + ' RES' + (j+1) + ' -->\\{\\{fb r\\|[\\s]*s[\\s]*=[\\s]*(\\{\\{[^{}]*\\}\\})\\}\\}', 'g');
s = s.replace(rp, '|match_' + teams[i] + '_' + teams[j] + '=$1\n<!-- FB R2 T' + (i+1) + ' RES' + (j+2) + ' -->');
rp = new RegExp('<!-- FB R2 T' + (i+1) + ' RES' + (j+1) + ' -->\\{\\{fb r\\|[\\s]*s[\\s]*=[\\s]*((?:[^\\{\\}\\|\\[\\]]|\\[\\[[^\\[\\]]*\\]\\]|\\{\\{[^{}]*\\}\}|\\[http[^\\[\\]]*\\])*)[\\s]*\\|[\\s]*nt[\\s]*=[\\s]*((?:\\{\\{[^{}]*\\}\\}|[^\\{\\}\\|])*)\\}\\}', 'g');
s = s.replace(rp, '|match_' + teams[i] + '_' + teams[j] + '=$1\n|match_' + teams[i] + '_' + teams[j] + '_note=$2\n<!-- FB R2 T' + (i+1) + ' RES' + (j+2) + ' -->');
rp = new RegExp('<!-- FB R2 T' + (i+1) + ' RES' + (j+1) + ' -->\\{\\{fb r\\|[\\s]*s[\\s]*=[\\s]*((?:[^\\{\\}\\|\\[\\]]|\\[\\[[^\\[\\]]*\\]\\]|\\{\\{[^{}]*\\}\}|\\[http[^\\[\\]]*\\])*)[\\s]*\\}\\}', 'g');
s = s.replace(rp, '|match_' + teams[i] + '_' + teams[j] + '=$1\n<!-- FB R2 T' + (i+1) + ' RES' + (j+2) + ' -->');
rp = new RegExp('<!-- FB R2 T' + (i+1) + ' RES' + (j+1) + ' -->\\{\\{fb r\\|[\\s]*gf[\\s]*=[\\s]*([^\\{\\}\\|]*)[\\s]*\\|[\\s]*ga[\\s]*=[\\s]*([^\\{\\}\\|]*)\\|[\\s]*ma[\\s]*=[\\s]*([^\\{\\}\\|]*)\\}\\}', 'g');
s = s.replace(rp, '|match_' + teams[i] + '_' + teams[j] + '=[[$3|$1–$2]]\n<!-- FB R2 T' + (i+1) + ' RES' + (j+2) + ' -->');
rp = new RegExp('<!-- FB R2 T' + (i+1) + ' RES' + (j+1) + ' -->\\{\\{fb r\\|[\\s]*gf[\\s]*=[\\s]*([^\\{\\}\\|]*)[\\s]*\\|[\\s]*ga[\\s]*=[\\s]*([^\\{\\}\\|]*)\\|[\\s]*ma[\\s]*=[\\s]*([^\\{\\}\\|]*)[\\s]*\\|[\\s]*nt[\\s]*=[\\s]*((?:\\{\\{[^{}]*\\}\\}|[^\\{\\}\\|])*)\\}\\}', 'g');
s = s.replace(rp, '|match_' + teams[i] + '_' + teams[j] + '=[[$3|$1–$2]]\n|match_' + teams[i] + '_' + teams[j] + '_note=$4\n<!-- FB R2 T' + (i+1) + ' RES' + (j+2) + ' -->');
rp = new RegExp('<!-- FB R2 T' + (i+1) + ' RES' + (j+1) + ' -->\\|\\|*((?:[^\\r\\n\\[\\]\\|\\{\\}]|\\{\\{[^{}]*\\}\\}|\\[\\[[^\\[\\]]*\\]\\])*)([\\r\\n]!|[\\r\\n]?\\|)', 'g');
s = s.replace(rp, '|match_' + teams[i] + '_' + teams[j] + '=$1\n<!-- FB R2 T' + (i+1) + ' RES' + (j+2) + ' -->$2');
}
}
rt = new RegExp('<!-- FB R2 T' + (i+1) + ' RES[0-9]+ -->');
s = s.replace(rt, '<!-- FB R2 ROW' + (i+2) + ' -->');
}
s = s.replace(/(<!-- FB R2 ROW[0-9]+ -->)[\s]*<!--[^<>]*-->[\s]*/g, '$1');
s = s.replace(/(<!-- FB R2 ROW[0-9]+ -->)[\s]*![\s\|]*/g, '$1');
s = s.replace(/(<!-- FB R2 ROW[0-9]+ -->)[\s]*\|\-[^\r\n]*[\r\n]/g, '$1');
s = s.replace(/<!-- FB R2 ROW[0-9]+ -->[\t ]*[\r\n]*[\t ]*[\r\n]*\{\{[_ ]*[Ff][b][_ ]+(?:cs|r2?)[_ ]+footer[^{}\|]*/g, '|update=complete\n|source=\n<!-- FB FOOTER2 -->');
s = s.replace(/<!-- FB R2 ROW[0-9]+ -->[\t ]*[\r\n]*[\t ]*[\r\n]*(?:\|\}|\{\{end\}\})/g, '\n|update=complete|source=\n}' + '}');
for (var kf=0; kf<5; kf++) {
s = s.replace(/(<!-- FB FOOTER2 -->)[\t ]*[\r\n]*[\t ]*(\|[ ]*s)[ ]*(=(?:\{\{[^\{\}]*\}\}|\[http[^\[\]]*\]|\[\[[^\[\]]*\]\]|[^\{\}\|\[\]])*)/g, '$2ource$3\n$1');
s = s.replace(/(<!-- FB FOOTER2 -->)[\t ]*[\r\n]*[\t ]*(\|[ ]*u)[ ]*(=(?:\{\{[^\{\}]*\}\}|\[http[^\[\]]*\]|\[\[[^\[\]]*\]\]|[^\{\}\|\[\]])*)/g, '$2pdate$3\n$1');
s = s.replace(/(<!-- FB FOOTER2 -->)[\t ]*[\r\n]*[\t ]*\|[\t ]*ma[\t ]*=[a-z\t \r\n]*(\||\}\})/g, '$1$2');
s = s.replace(/(<!-- FB FOOTER2 -->)[\t ]*[\r\n]*[\t ]*\|[\t ]*a[\t ]*=[a-z\t \r\n]*(\||\}\})/g, '$1$2');
s = s.replace(/(<!-- FB FOOTER2 -->)[\t ]*[\r\n]*[\t ]*\|[\t ]*date[\t ]*=[A-Za-z,0-9\t \r\n]*(\||\}\})/g, '$1$2');
s = s.replace(/(<!-- FB FOOTER2 -->)[\t ]*[\r\n]*[\t ]*\|[\t ]*nt[\t ]*=[\t ]*[\r\n]*[\t ]*(\||\}\})/g, '$1$2');
s = s.replace(/(<!-- FB FOOTER2 -->)[\t ]*[\r\n]*[\t ]*(\|[\t ]*nt[\t ]*=(?:\[\[[^\[\]]*\]\]|\{\{[^{}]*\}\}|[^\[\]\{\}\|]|[\r\n])*)(\||\}\})/g, '\n$2\n$1$3');
s = s.replace(/(<!-- FB FOOTER2 -->)[\t\|\r\n ]*(\}\})/g, '$2');
}
s = s.replace(/\|[\s]*source[\s]*=[\s]*[\r\n]([^{}]*\|[ ]*source[ ]*=)/g, '$1');
s = s.replace(/\|[\s]*update[\s]*=[\s]*complete[ ]*[\r\n]([^{}]*\|[\s]*update[\s]*=)/g, '$1');
// s = s.replace(/(\|[\s]*name_)([^=\s]*)([\s]*=[\s]*\[\[[^\[\]\|]*)\|\2(\]\])/g, '$1$2$3$4');
s = s.replace(/(\|[\s]*team[0-9]+[\s]*=[^\r\n]*)[\r\n](\|[\s]*team[0-9]+[\s]*=)/g, '$1$2');
s = s.replace(/(\|[\s]*team[0-9]+[\s]*=[^\r\n]*)[\r\n](\|[\s]*team[0-9]+[\s]*=)/g, '$1$2');
s = s.replace(/(\|[\s]*team(?:5|10|15|20|25)[ ]*=[^=\|\r\n]*)(\|)/g, '$1\n$2');
s = s.replace(/(\|match_[^\r\n]*[\r\n])(\|(?:update|source|name_))/g, '$1\n$2');
s = s.replace(/[\s]*[\r\n][\t ]*[\r\n]/g, '\n\n');
lt = '';
while(lt != s) {
lt = s;
s = s.replace(/(\|[ ]*match_[^_=]*_[^_=]*_note[ ]*=[^\r\n]*[\r\n])([\s]*\|[ ]*(?:name_[^=]*|match_[^_=]*_[^_=]*)[ ]*=[^\r\n]*[\r\n])/g, '$2$1');
}
if (s.search(/<!-- FB R/g) >= 0) {
alert(s);
return oldtext;
}
return s;
}
// -------------------------------------------------------------------------------- //
function wpRugby(s)
{
var lt = '';
if(s.search(/<!--[ ]*RUGBY TABLE[ ]*-->/gi) >= 0) {
while (lt != s) {
lt = s;
s = s.replace(/([\r\n]\|\-[^\r\n]*[\r\n]\|[^\-][^\r\n]*)[\r\n]\|([^\-\}])/gi, '$1|| $2');
}
s = s.replace(/(<!--[ ]*RUGBY TABLE[ ]*-->[\t ]*[\r\n]\|\-[^\r\n]*[\r\n])(\|[ ]*(?:align[ ]*=["' ]*left|style="text\-align:left))/g, '$1<!-- RUGBY POS 1 -->| 1 |$2');
lt = '';
k = 1;
while (lt != s) {
lt = s;
var re = new RegExp('<!--[ ]*RUGBY POS[ ]*' + k + '[ ]*-->([^\\r\\n]*[\\r\\n]\\|\\-[^\\r\\n]*[\\r\\n])(\\|[ ]*(?:align[ ]*=["\' ]*left|style="text\\-align:left))', 'gi');
k = k + 1;
s = s.replace(re, '$1| ' + k + ' <!-- RUGBY POS ' + k + ' -->|$2');
}
s = s.replace(/<!--[ ]*RUGBY[ ]*POS[ ]*[0-9]*[ ]*-->/g, '');
lt = '';
}
while (lt != s) {
lt = s;
s = s.replace(/(<!--[ ]*RUGBY TABLE[ ]*-->[\t ]*[\r\n])[\t ]*[\r\n]/g, '$1');
s = s.replace(/(<!--[ ]*RUGBY TABLE[ ]*-->[\t ]*[\r\n])[\t ]*\|\-[\t ]*[\r\n]/g, '$1');
s = s.replace(/(<!--[ ]*RUGBY TABLE[ ]*-->[\t ]*[\r\n][\t ]*\|\-[^\r\n]*)align[\t ]*=[\t'" ]*center[\t'" ]*/gi, '$1');
s = s.replace(/(<!--[ ]*RUGBY TABLE[ ]*-->[\t ]*[\r\n][\t ]*\|\-[^\r\n]*)bgcolor[\t ]*=[\t'" ]*#?ffffff[\t'" ]*/gi, '$1');
s = s.replace(/(<!--[ ]*RUGBY TABLE[ ]*-->[\t ]*[\r\n])[\t ]*\|\-[ ]*style=\"background(?:\-color|):[\t ]*#([^;"]*);?(?:text\-align[^;"]*;?|)"[ ]*([\r\n]\|[ ]*)([0-9]+)/g, '\n| col_$2 = $2 | text_$2 =\n|result$4 = $2$1$3$4');
s = s.replace(/(<!--[ ]*RUGBY TABLE[ ]*-->[\t ]*[\r\n])[\t ]*\|\-[ ]*bgcolor[ ]*=['" #]*([^'"; ]*)[ ]*([\r\n]\|[ ]*)([0-9]+)/g, '\n| col_$2 = $2 | text_$2 =\n|result$4 = $2$1$3$4');
s = s.replace(/(<!--[ ]*RUGBY TABLE[ ]*-->[\t ]*[\r\n])[\t ]+/gi, '$1');
s = s.replace(/(<!--[ ]*RUGBY TABLE[ ]*-->[\t ]*[\r\n][\t ]*\|)\|/gi, '$1');
s = s.replace(/(<!--[ ]*RUGBY TABLE[ ]*-->[\t ]*[\r\n][\t ]*\|[^\r\n]*\|\|)[ ]*([0-9]+)[ ]*([\r\n])/gi, '$1 \'\'\'$2\'\'\'$3');
s = s.replace(/(<!--[ ]*RUGBY TABLE[ ]*-->[\t ]*[\r\n])[\t ]*\|[ ]*([0-9]+)[ ]*\|\|[ ]*(?:align[^\|]*|style[^\|]*)\|[\t ]*(?:'''|)(\{\{[^{}]*\}\}|(?:\{\{flag[^{}]*\}\}[ ]*|)\[\[[^\[\]]*\]\][ ]*['\(A-Z0-9\)]*|[A-Z][a-z ]*['\(A-Z\)]*)[\t ]*\|\|[\t ]*[0-9]+[\t ]*\|\|[\t ]*([0-9]+)[\t ]*\|\|[\t ]*([0-9]+)[\t ]*\|\|[\t ]*([0-9]+)[\t ]*\|\|[\t ]*([0-9]+)[\t ]*\|\|[\t ]*([0-9]+)[\t ]*\|\|[^\|]*\|\|[\t ]*/gi, '\n| team$2 = $2 | name_$2 = $3\n| win_$2 = $4| draw_$2 = $5| loss_$2 = $6| pf_$2 = $7| pa_$2 = $8| tf_$2 = $1');
s = s.replace(/tf_([0-9]+)[ ]*=[ ]*(<!--[ ]*RUGBY TABLE[ ]*-->)[\t ]*[\r\n]*[\t ]*([0-9]*)[\t ]*\|\|[\t ]*([0-9]*)[\t ]*\|\|[\t ]*([0-9]+)[ ]*\|\|[\t ]*([0-9]+)[ ]*\|\|[\t ]*'''[\t ]*[0-9]+[\t ]*'''[\t ]*/g, 'tf_$1 = $3| ta_$1 = $4 | tb_$1 = $5 | lb_$1 = $6$2');
s = s.replace(/tf_([0-9]+)[ ]*=[ ]*(<!--[ ]*RUGBY TABLE[ ]*-->)[\t ]*[\r\n]*[\t ]*([0-9]*)[\t ]*\|\|[\t ]*([0-9]*)[\t ]*\|\|[\t ]*([0-9]+)[ ]*\|\|[\t ]*'''[ ]*[0-9]+[\t ]*'''[\t ]*/g, 'tf_$1 = $3| tb_$1 = $4 | lb_$1 = $5$2');
s = s.replace(/tf_([0-9]+)[ ]*=[ ]*(<!--[ ]*RUGBY TABLE[ ]*-->)[\t ]*[\r\n]*[\t ]*([0-9]*)[\t ]*\|\|[\t ]*([0-9]+)[\t ]*\|\|[\t ]*'''[\t ]*[0-9]+[\t ]*'''[ ]*/g, 'tb_$1 = $3| lb_$1 = $4$2');
s = s.replace(/tf_([0-9]+)[ ]*=[ ]*(<!--[ ]*RUGBY TABLE[ ]*-->)[\t ]*[\r\n]*[\t ]*([0-9]*)[\t ]*\|\|[\t ]*'''[\t ]*[0-9]+[ ]*'''[ ]*/g, 'b_$1 = $3$2');
s = s.replace(/(\|[ ]name_)([0-9]+)([ ]*=[^\r\n]*)\'\'\'\((?:\'\'\'|)([CPR])(?:\'\'\'|)\)\'\'\'/gi, '$1$2$3|status_$2=$4');
s = s.replace(/(\|[ ]name_)([0-9]+)([ ]*=[^\r\n]*)(?:\'\'\'|)\((?:\'\'\'|)([CPR])(?:\'\'\'|)\)(?:\'\'\'|)/gi, '$1$2$3|status_$2=$4');
s = s.replace(/(\|[ ]*(?:col_|result[0-9])[^\r\n]*[\r\n])(\|[ ]*(?:team[0-9]+|win_)[^\r\n]*[\r\n])/g, '$2$1');
}
if(s.search(/<!--[ ]*RUGBY TABLE[ ]*-->/gi) >= 0) {
lt = '';
var i = 1;
while (lt != s) {
lt = s;
var a = s.match(/col_([a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9])[ ]*=/i);
if (a) {
var rexp = new RegExp('col_' + a[1] + '[ ]*=[ ]*' + a[1], 'gi');
s = s.replace(rexp, 'col_RESULT' + i + ' = #' + a[1]);
rexp = new RegExp('text_' + a[1] + '[ ]*=', 'gi');
s = s.replace(rexp, 'text_RESULT' + i + ' =');
rexp = new RegExp('(result[0-9]+)[ ]*=[ ]*' + a[1], 'gi');
s = s.replace(rexp, '$1 = RESULT' + i);
}
i = i + 1;
}
}
return s;
}
// -------------------------------------------------------------------------------- //
function wpVB(s)
{
s = s.replace(/(\{\{[_ ]*[Vv]b[_ ]+cl[0-9]*[_ ]+team(?:[^{}]*\|\{\{[^{}]*\}\})*)\{\{[_ ]*nowrap[_ ]*\|((?:\{\{[^{}=]*\}\}|[^{}])*)\}\}/g, '$1$2');
s = s.replace(/(\{\{[_ ]*[Vv]b[_ ]+cl[0-9]*[_ ]+team(?:[^{}]|\{\{[^{}]*\}\})*)(\|[\t ]*t[\t ]*=(?:[^{}]|\{\{[^{}]*\}\})*)(\|[\t ]*nat[\t ]*=[\t ]*[A-Z]+)[\t ]*(\||\}\})/g, '$1$3$2$4');
s = s.replace(/(\{\{[_ ]*[Vv]b[_ ]+cl[0-9]*[_ ]+team[^{}]*)\|[\t ]*nat[\t ]*=[\t ]*([A-Z]+)[\t ]*(\|[\t ]*t[\t ]*=)[\t ]*/g, '$1$3 {'+'{flagicon|$2}'+'} ');
s = s.replace(/(\{\{[_ ]*[Vv]b[_ ]+cl[0-9]*[_ ]+team(?:[^{}]|\{\{[^{}]*\}\})*)\|[\t ]*nat[\t ]*=[\t ]*(\||\}\})/g, '$1$2');
var lt = '';
while (s != lt) {
lt = s;
s = s.replace(/(\{\{[_ ]*[Vv]b[_ ]+cl(?:\{\{(?:\{\{[^{}]*\}\}|[^{}])*\}\}|[^{}])*)[\r\n]/g, '$1 ');
}
if(s.search(/[Vv]b[_ ]+cl3[_ ]+team/gi) >= 0 ) {
s = s.replace(/(\{\{)[_ ]*[Vv]b[_ ]+cl[0-9]*[_ ]+header[^{}]*\}\}/g, '$1#invoke:Sports table|main|style=Volleyball\n|res_col_header=RESCOLHEADER\n|ranking_style=none|setpoints_before_sets=y\n|update=complete');
} else if (s.search(/[Vv]b[_ ]+cl(?:91|4)[_ ]+team/gi) >=0 ) {
s = s.replace(/(\{\{)[_ ]*[Vv]b[_ ]+cl[0-9]*[_ ]+header[^{}]*\}\}/g, '$1#invoke:Sports table|main|style=Volleyball\n|res_col_header=RESCOLHEADER\n|ranking_style=points\n|update=complete');
} else if (s.search(/[Vv]b[_ ]+cl6[_ ]+team/gi) >=0 ) {
s = s.replace(/(\{\{)[_ ]*[Vv]b[_ ]+cl[0-9]*[_ ]+header[^{}]*\}\}/g, '$1#invoke:Sports table|main|style=Volleyball\n|res_col_header=RESCOLHEADER\n|ranking_style=wins|setpoints_before_sets=y\n|win3points=5|win4points=4|win5points=3|loss5points=2|loss4points=1\n|update=complete');
} else if (s.search(/[Vv]b[_ ]+cl7[_ ]+team/gi) >=0 ) {
s = s.replace(/(\{\{)[_ ]*[Vv]b[_ ]+cl[0-9]*[_ ]+header[^{}]*\}\}/g, '$1#invoke:Sports table|main|style=Volleyball\n|res_col_header=RESCOLHEADER\n|ranking_style=points\n|update=complete');
} else if (s.search(/[Vv]b[_ ]+cl9[_ ]+team/gi) >=0 ) {
s = s.replace(/(\{\{)[_ ]*[Vv]b[_ ]+cl[0-9]*[_ ]+header[^{}]*\}\}/g, '$1#invoke:Sports table|main|style=Volleyball\n|res_col_header=RESCOLHEADER\n|ranking_style=wins\n|update=complete');
} else {
s = s.replace(/(\{\{)[_ ]*[Vv]b[_ ]+cl[0-9]*[_ ]+header[^{}]*\}\}/g, '$1#invoke:Sports table|main|style=Volleyball\n|res_col_header=RESCOLHEADER\n|ranking_style=points|bwinpoints=2|blosspoints=1\n|update=complete');
}
s = s.replace(/\{\{[_ ]*[Vv]b[_ ]+cl[2345679]?[_ ]+team[_ ]*\|[\|\t ]*p[\t ]*=[\t ]*([0-9]+)[\t ]*\|[\|\t ]*t[\t ]*=/g, '| team$1 = $1 | name_$1 =');
s = s.replace(/\{\{[_ ]*[Vv]b[_ ]+cl[2345679]?[_ ]+team[_ ]*\|[\|\t ]*p[\t ]*=[\t ]*(\{\{(?:gold|silver|bronze)0?)([1-3])(\}\})[\t ]*\|[\|\t ]*t[\t ]*=/gi, '| team$2 = $2 | pos_$2 = $1$2$3 | name_$2 =');
var lt = '';
while(lt != s) {
lt = s;
s = s.replace(/\|[ ]*(\|[ ]*(?:name|mw|ml|bwin|bloss|swin|sloss|sp?w|sp?l|win[345]s|loss[345]s|bc)[a-z0-9_]*=)/g, '$1');
s = s.replace(/\|[ ]*bc[ ]*=[ ]*(\||\}\})/g, '$1');
s = s.replace(/(\|[ ]*(?:name|mw|ml|bwin|bloss|swin|sloss|sp?w|sp?l|win[345]s|loss[345]s))(_[^=]*=)((?:[^\r\n\|\{\}\[\]]|\{\{[^{}]*\}\}|\[\[[^\[\]]*\]\])*\|[ ]*)w3_0[ ]*=/g, '$1$2$3win3s$2');
s = s.replace(/(\|[ ]*(?:name|mw|ml|bwin|bloss|swin|sloss|sp?w|sp?l|win[345]s|loss[345]s))(_[^=]*=)((?:[^\r\n\|\{\}\[\]]|\{\{[^{}]*\}\}|\[\[[^\[\]]*\]\])*\|[ ]*)w3_1[ ]*=/g, '$1$2$3win4s$2');
s = s.replace(/(\|[ ]*(?:name|mw|ml|bwin|bloss|swin|sloss|sp?w|sp?l|win[345]s|loss[345]s))(_[^=]*=)((?:[^\r\n\|\{\}\[\]]|\{\{[^{}]*\}\}|\[\[[^\[\]]*\]\])*\|[ ]*)w3_2[ ]*=/g, '$1$2$3win5s$2');
s = s.replace(/(\|[ ]*(?:name|mw|ml|bwin|bloss|swin|sloss|sp?w|sp?l|win[345]s|loss[345]s))(_[^=]*=)((?:[^\r\n\|\{\}\[\]]|\{\{[^{}]*\}\}|\[\[[^\[\]]*\]\])*\|[ ]*)l0_3[ ]*=/g, '$1$2$3loss3s$2');
s = s.replace(/(\|[ ]*(?:name|mw|ml|bwin|bloss|swin|sloss|sp?w|sp?l|win[345]s|loss[345]s))(_[^=]*=)((?:[^\r\n\|\{\}\[\]]|\{\{[^{}]*\}\}|\[\[[^\[\]]*\]\])*\|[ ]*)l1_3[ ]*=/g, '$1$2$3loss4s$2');
s = s.replace(/(\|[ ]*(?:name|mw|ml|bwin|bloss|swin|sloss|sp?w|sp?l|win[345]s|loss[345]s))(_[^=]*=)((?:[^\r\n\|\{\}\[\]]|\{\{[^{}]*\}\}|\[\[[^\[\]]*\]\])*\|[ ]*)l2_3[ ]*=/g, '$1$2$3loss5s$2');
if (s.search(/(?:mw3|ml3)[ ]*=/g) >= 0 ) {
s = s.replace(/(\|[ ]*(?:name|mw|ml|bwin|bloss|swin|sloss|sp?w|sp?l|win[345]s|loss[345]s))(_[^=]*=)((?:[^\r\n\|\{\}\[\]]|\{\{[^{}]*\}\}|\[\[[^\[\]]*\]\])*\|[ ]*)mw[ ]*=/g, '$1$2$3win3s$2');
s = s.replace(/(\|[ ]*(?:name|mw|ml|bwin|bloss|swin|sloss|sp?w|sp?l|win[345]s|loss[345]s))(_[^=]*=)((?:[^\r\n\|\{\}\[\]]|\{\{[^{}]*\}\}|\[\[[^\[\]]*\]\])*\|[ ]*)mw2[ ]*=/g, '$1$2$3win4s$2');
s = s.replace(/(\|[ ]*(?:name|mw|ml|bwin|bloss|swin|sloss|sp?w|sp?l|win[345]s|loss[345]s))(_[^=]*=)((?:[^\r\n\|\{\}\[\]]|\{\{[^{}]*\}\}|\[\[[^\[\]]*\]\])*\|[ ]*)mw3[ ]*=/g, '$1$2$3win5s$2');
s = s.replace(/(\|[ ]*(?:name|mw|ml|bwin|bloss|swin|sloss|sp?w|sp?l|win[345]s|loss[345]s))(_[^=]*=)((?:[^\r\n\|\{\}\[\]]|\{\{[^{}]*\}\}|\[\[[^\[\]]*\]\])*\|[ ]*)ml[ ]*=/g, '$1$2$3loss3s$2');
s = s.replace(/(\|[ ]*(?:name|mw|ml|bwin|bloss|swin|sloss|sp?w|sp?l|win[345]s|loss[345]s))(_[^=]*=)((?:[^\r\n\|\{\}\[\]]|\{\{[^{}]*\}\}|\[\[[^\[\]]*\]\])*\|[ ]*)ml2[ ]*=/g, '$1$2$3loss4s$2');
s = s.replace(/(\|[ ]*(?:name|mw|ml|bwin|bloss|swin|sloss|sp?w|sp?l|win[345]s|loss[345]s))(_[^=]*=)((?:[^\r\n\|\{\}\[\]]|\{\{[^{}]*\}\}|\[\[[^\[\]]*\]\])*\|[ ]*)ml3[ ]*=/g, '$1$2$3loss5s$2');
} else {
s = s.replace(/(\|[ ]*(?:name|mw|ml|bwin|bloss|swin|sloss|sp?w|sp?l|win[345]s|loss[345]s))(_[^=]*=)((?:[^\r\n\|\{\}\[\]]|\{\{[^{}]*\}\}|\[\[[^\[\]]*\]\])*\|[ ]*)mw[ ]*=/g, '$1$2$3bwin$2');
s = s.replace(/(\|[ ]*(?:name|mw|ml|bwin|bloss|swin|sloss|sp?w|sp?l|win[345]s|loss[345]s))(_[^=]*=)((?:[^\r\n\|\{\}\[\]]|\{\{[^{}]*\}\}|\[\[[^\[\]]*\]\])*\|[ ]*)mw2[ ]*=/g, '$1$2$3swin$2');
s = s.replace(/(\|[ ]*(?:name|mw|ml|bwin|bloss|swin|sloss|sp?w|sp?l|win[345]s|loss[345]s))(_[^=]*=)((?:[^\r\n\|\{\}\[\]]|\{\{[^{}]*\}\}|\[\[[^\[\]]*\]\])*\|[ ]*)ml[ ]*=/g, '$1$2$3bloss$2');
s = s.replace(/(\|[ ]*(?:name|mw|ml|bwin|bloss|swin|sloss|sp?w|sp?l|win[345]s|loss[345]s))(_[^=]*=)((?:[^\r\n\|\{\}\[\]]|\{\{[^{}]*\}\}|\[\[[^\[\]]*\]\])*\|[ ]*)ml2[ ]*=/g, '$1$2$3sloss$2');
}
s = s.replace(/(\|[ ]*(?:name|mw|ml|bwin|bloss|swin|sloss|sp?w|sp?l|win[345]s|loss[345]s))(_[^=]*=)((?:[^\r\n\|\{\}\[\]]|\{\{[^{}]*\}\}|\[\[[^\[\]]*\]\])*\|[ ]*)spw[ ]*=/g, '$1$2$3spw$2');
s = s.replace(/(\|[ ]*(?:name|mw|ml|bwin|bloss|swin|sloss|sp?w|sp?l|win[345]s|loss[345]s))(_[^=]*=)((?:[^\r\n\|\{\}\[\]]|\{\{[^{}]*\}\}|\[\[[^\[\]]*\]\])*\|[ ]*)spl[ ]*=/g, '$1$2$3spl$2');
s = s.replace(/(\|[ ]*(?:name|mw|ml|bwin|bloss|swin|sloss|sp?w|sp?l|win[345]s|loss[345]s))(_[^=]*=)((?:[^\r\n\|\{\}\[\]]|\{\{[^{}]*\}\}|\[\[[^\[\]]*\]\])*\|[ ]*)sw[ ]*=/g, '$1$2$3sw$2');
s = s.replace(/(\|[ ]*(?:name|mw|ml|bwin|bloss|swin|sloss|sp?w|sp?l|win[345]s|loss[345]s))(_[^=]*=)((?:[^\r\n\|\{\}\[\]]|\{\{[^{}]*\}\}|\[\[[^\[\]]*\]\])*\|[ ]*)sl[ ]*=/g, '$1$2$3sl$2');
s = s.replace(/(\|[ ]*team)([0-9]+)([ ]*=(?:[^\r\n\{\}]|\{\{[^{}]*\}\})*)\|[\t ]*bc[\t ]*=[\t "']*(#[^\|\r\n '"]*|gold|silver)['" ]*/g, '$1$2$3 | result$2 = RESULT$2 | col_RESULT$2 = $4 | text_RESULT$2 =');
s = s.replace(/(\|[ ]*(?:team[0-9]+|result[0-9]+)[ ]*=(?:[^\r\n\{\}]|\{\{[^{}]*\}\})*)\|?[\t ]*\}\}/g, '$1');
s = s.replace(/([0-9=\}]+)[\t ]*(\|[\t ]*result[0-9]+[\t ]*=)/g, '$1\n$2');
s = s.replace(/[\t ]*(\|[\t ]*result[0-9]+[\t ]*=[\t ]*RESULT[0-9]+)[\t ]*[\r\n][\t ]*(\|[\t ]*col_)/g, '$1$2');
s = s.replace(/(\|[\t ]*name_[^=]*=(?:\[\[[^\[\]]*\]\]|\{\{[^{}]*\}\}|[^\[\]\{\}\|\r\n])*)(\|[\t ]*(?:bwin_|win3s))/g, '$1\n$2');
s = s.replace(/([\r\n][\t ]*\|[\t ]*(?:win[345]s|bwin_|result[0-9]+)[^\r\n]*)([\r\n][\t ]*\|[\t ]*(?:team[0-9]+)[ ]*=[^\r\n]*)/g, '$2$1');
s = s.replace(/([\r\n][\t ]*\|[\t ]*(?:result[0-9]+)[^\r\n]*)([\r\n][\t ]*\|[\t ]*(?:team[0-9]+|bwin_|win[345]s_)[^\r\n]*)/g, '$2$1');
s = s.replace(/([\r\n][\t ]*\|[\t ]*(?:result[0-9]+)[^\r\n]*)([\r\n][\t ]*\|[\t ]*(?:bwin_|win[345]s_)[^\r\n]*)/g, '$2$1');
s = s.replace(/([\r\n][\t ]*\|[\t ]*result[0-9]+[\t ]*=[^\r\n]*)([\r\n][\t ]*\|[\t ]*win3s_[^\r\n]*)/gm, '$2$1');
s = s.replace(/([\r\n]\|[\t ]*(?:name|mw|ml|bwin|bloss|swin|sloss|sp?w|sp?l|win[345]s|loss[345]s|result[0-9]+|col_|text_)[^\r\n]*)[\r\n]?\{\{end\}\}/g, '$1\n|source=\n}'+'}');
s = s.replace(/([\r\n]\|[\t ]*(?:name|mw|ml|bwin|bloss|swin|sloss|sp?w|sp?l|win[345]s|loss[345]s|result[0-9]+|col_|text_)[^\r\n]*)[\r\n]?\|\}([^\}])/g, '$1\n|source=\n}'+'}$2');
}
return s;
}
// -------------------------------------------------------------------------------- //
function wpFbGenFix(s)
{
var lt='';
s = s.replace(/\{\{subst:void\}\}/g, '');
while (s.search(/(\[\[[^\|\[\]_]*)_/g) >= 0 ) {
s = s.replace(/(\[\[[^\|\[\]_]*)_/g, '$1 ');
}
while (s.search(/(\{\{)[_ ]*([Ff]b[_ ]+cl(?:[^{}\r\n]|\{\{[^{}]*\}\})*)[\r\n]/g) >= 0 ) {
s = s.replace(/(\{\{)[_ ]*([Ff]b[_ ]+cl(?:[^{}\r\n]|\{\{[^{}]*\}\})*)[\r\n]/g, '$1$2');
}
if(s.search(/bgcolor="#FFFFFF" cellpadding="1" cellspacing="0"/g) >= 0) {
s = s.replace(/bgcolor="#FFFFFF" cellpadding="1" cellspacing="0"/g, 'class="wikitable" style="text-align:center"');
s = s.replace(/(\{\|[ ]*class[ ]*=[" ]*wikitable[^\r\n]*[\r\n]\|\-)[^\r\n]*([\r\n]!)/g, '$1$2');
s = s.replace(/(\|\-[^\r\n]*)align[ ]*=[" ]*center[" ]*/g, '$1');
s = s.replace(/(\|\-[^\r\n]*)valign[ ]*=[" ]*top[" ]*/g, '$1');
}
s = s.replace(/[\r\n]\{\|(?:width[ ]*=[" ]*100%[" ]*|[\t ])*[\r\n]\|[\t ]*([\r\n][\*:])/g, '\n{'+'{colbegin|colwidth=18em}'+'}<!-- FB LIST -->$1');
lt = '';
while(s != lt) {
lt = s;
s = s.replace(/(<!-- FB LIST -->)([\*:][^\r\n]*[\r\n]|[\t ]*[\r\n])/g, '$2$1');
s = s.replace(/(<!-- FB LIST -->)\|[\t ]*[\r\n]/g, '$1');
s = s.replace(/<!-- FB LIST -->\|\}/g, '{'+'{colend}'+'}');
}
s = s.replace(/(\{\{)iht header(\}\})/g, '$1fb cl2 header$2');
s = s.replace(/(\{\{)iht team/g, '$1fb cl2 team');
s = s.replace(/in season ([0-9][0-9][0-9][0-9])\/[0-9][0-9]([0-9][0-9])/g, 'for the $1–$2 season');
s = s.replace(/in season ([0-9][0-9][0-9][0-9])\/([0-9][0-9])/g, 'for the $1–$2 season');
s = s.replace(/in season ([0-9][0-9][0-9][0-9])\./g, 'for the $1 season.');
s = s.replace(/<!--[\s]*For instructions how to use(?:[\s]|[^<>])*-->/g, '');
s = s.replace(/(in the [0-9][0-9][0-9][0-9])[\/\-–][0-9][0-9]([0-9][0-9] season)/g, '$1–$2');
s = s.replace(/( 1999–)(00 season)/g, '$120$2');
s = s.replace(/( 1899–)(00 season)/g, '$119$2');
// s = s.replace(/(\{\{location map\+[^\r\n]*\|[ ]*float[ ]*=[ ]*)left((?:[\r\n]|\{\{[^{}]*\}\}|[^{}])*\}\})[\s]*(\{\{location map\+[^\r\n]*\|[ ]*float[ ]*=[ ]*right(?:[\r\n]|\{\{[^{}]*\}\}|[^{}])*\}\})[\s]*\{\{(?:\-|clear)\}\}/g, '$3\n$1none$2');
s = s.replace(/([0-9]+)°[\s]+(league|title|season)/g, '{'+'{subst:ordinal|$1}'+'} $2');
s = s.replace(/(\[\[(?:Barrow|Bradford City|Bradford Park Avenue|Halifax Town|Huddersfield Town|Newport County|Oldham Athletic|Rochdale|Sunderland|Swansea City|Workington)) F\.C\.(\|)/g, '$1 A.F.C.$2');
s = s.replace(/(\[\[Southend) (F\.C\.\|)/g, '$1 United $2');
s = s.replace(/(\[\[)Manchester United F\.C\.(\|Newton Heath)/g, '$1History of Manchester United F.C. (1878–1945)$2');
s = s.replace(/[\t ]*Kartposition markör/g, 'Location map~');
s = s.replace(/[\t ]*Kartposition start([^{}]*)\}\}/g, 'Location map+$1|places=');
s = s.replace(/\{\{[\t ]*Kartposition slut[^=]*\|[ ]*undertext[ ]*=[^\|\{\}]*/g, '|caption=Location of the participating clubs');
s = s.replace(/\|[ ]*markör[ ]*=[ ]*\|/g, '|');
s = s.replace(/\|[ ]*plats[ ]*=/g, '|label=');
s = s.replace(/(\{\{[ ]*Location map[^{}]*<\/?)span/g, '$1div');
s = s.replace(/(\{\{[ ]*Location map[^{}]*<\/?)span/g, '$1div');
s = s.replace(/(Location map(?:\+|~))[\t ]*\|[\t ]*Norwegen Süd/g, '$1|Norway South');
s = s.replace(/(Location map(?:\+|~))[\t ]*\|[\t ]*Norwegen/g, '$1|Norway');
s = s.replace(/(Location map(?:\+|~))[\t ]*\|[\t ]*södra Sverige/g, '$1|Sweden South');
s = s.replace(/(Location map(?:\+|~))[\t ]*\|[\t ]*södra halva Sverige/g, '$1|Sweden Southern');
s = s.replace(/(\{\{Location map[^{}]*)\|[\t ]*lat[\t ]*=[\t ]*([0-9]+)\/([0-9]+)\/([0-9]+)[\t \r\n]*\|[\t ]*long[\t ]*=[\t ]*([0-9]+)\/([0-9]+)\/([0-9]+)/g, '$1|coordinates={' + '{coord|$2|$3|$4|N|$5|$6|$7|E}' +'}');
s = s.replace(/(\{\{Location map[^{}]*\|[\t ]*position[\t ]*=[\t ]*)(?:11|12|1)([^0-9])/g, '$1top$2');
s = s.replace(/(\{\{Location map[^{}]*\|[\t ]*position[\t ]*=[\t ]*)(?:2|3|4)([^0-9])/g, '$1right$2');
s = s.replace(/(\{\{Location map[^{}]*\|[\t ]*position[\t ]*=[\t ]*)(?:5|6|7)([^0-9])/g, '$1bottom$2');
s = s.replace(/(\{\{Location map[^{}]*\|[\t ]*position[\t ]*=[\t ]*)(?:8|9|10)([^0-9])/g, '$1left$2');
s = s.replace(/\{\{[_ ]*[Pp]lain[_ ]*link[_ ]*\|([^{}\|=]*)\|([^{}\|=]*)\}\}/g, '[$1 $2]');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2?[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*\}\})[\t ]*\|\|/g, '$1\n|');
s = s.replace(/(\|[ ]*[fn]c)([ ]*=[ ]*YS[ ]*\|)/g, '$1l$2');
s = s.replace(/(\|[ ]*[fn]c)l?([ ]*=[ ]*)(?:Free[ ]*[Aa]gent|\[\[[^\[\]]*\|Free[ ]*[Aa]gent]\]|\[\[Free[ ]*[Aa]gent\]\])([ ]*\|)/g, '$1l$2Free agent$3');
s = s.replace(/(\|[ ]*[fn]c)([ ]*=[ ]*)[Rr]etired([ ]*\|)/g, '$1l$2Retired$3');
s = s.replace(/cl[\t ]*=[\t ]*<small>\[\[Youth system\]\]<\/small>[\t ]*\|[\t ]*[nf]cnat[ ]*=[ ]*\|/g, 'cl = YS |');
s = s.replace(/(\{\{[_ ]*(?:OneLeg|TwoLeg|[Ff]b[_ ])(?:\{\{[^{}]*\}\}|[^{}])*\}\}[\t ]*[\r\n][\r\n]*)\|\}([^\}])/g, '$1{' + '{end}' + '}$2');
s = s.replace(/([\r\n]\{\{[Cc]ol\-end\}\})([\r\n]\|\})/g, '$2$1');
s = s.replace(/(\{\{)[_ ]*[Ii]nfobox[_ ]+[Ff]ootball[_ ]+club[_ ]+season/gi, '$1Infobox football club season');
s = s.replace(/(\|[ ]*t[ ]*=[ ]*)([^\{\}\[\]\| ][^\{\}\[\]\|]*)\{\{!\}\}([^\{\}\[\]\|]*[^\{\}\[\]\| ])([\t ]*\||[\t ]*\}\})/g, '$1[[$2|$3]]$4');
s = s.replace(/_THIS_IS_A_PIPE_/g, '|');
s = s.replace(/<!--[ ]*CONVERT[ ]*FB[ ]*TEAM[ ]*-->/gi, '');
s = s.replace(/(\[\[)([^\[\]\|]*)\|\2(\]\])/g, '$1$2$3');
s = s.replace(/<(?:small|sup)>([0-9]*(?:st|nd|rd|th))<\/(?:small|sup)>/gi, '$1');
s = s.replace(/[\t ]*[\r\n]*[\t ]*[\r\n]*[\t ]*[\r\n]*(\{\{empty)/gi, '\n$1');
s = s.replace(/([\r\n])<sup>([^\r\n]*)<\/sup>[\t ]*[\r\n]/g, '$1<small>$2</small>$1');
s = s.replace(/([\r\n])<small>[0-9][ ]*(The system[^\r\n]*)<\/small>[\t ]*[\r\n][\t ]*[\r\n]*[\t ]*[\r\n]*<small>[0-9][ ]*(The points[^<>]*)<\/small>/g, '$1$2 $3');
s = s.replace(/([0-9]+[ ]*\|\|[ ]*[0-9]+[\*†‡ ]*)[ ]*\|\|[ ]*align[ ]*=[" ]*left[" ]*[ ]*\|/g, '$1\n| ');
s = s.replace(/([0-9]+[ ]*\|\|[ ]*[0-9]+[\*†‡ ]*)[ ]*\|\|[ ]*align[ ]*=[" ]*left[" ]*(rowspan)/g, '$1\n| $2');
//s = s.replace(/(squad[ ]*==[= ]*[\r\n][\t ]*[\r\n]*\{\|)[^\r\n]*[\r\n]/g, '$1 class="wikitable"<!-- FB -->');
//s = s.replace(/(<!-- FB -->)[\t ]*[\r\n]*(\|\-)[^\r\n]*([\r\n])/gi, '\n$2$3$1');
//s = s.replace(/<!-- FB -->\|(?:<span[^<>]*>|[ '])*([^<>'\r\n]*)(?:<\/span>|[ '])*([\r\n]\|\-)[^\r\n]*([\r\n]\|)/gi, '!$1$2$3');
//s = s.replace(/<!-- FB -->!/gi, '!');
//s = s.replace(/\{\{col\-begin\}\}[\t ]*[\r\n](\*|:)/gi, '{' + '{colbegin|colwidth=22em}' + '}\n$1');
//if(s.search(/\{\{[\s_]*colbegin/g) >= 0 ) {
// s = s.replace(/\{\{col\-[23]\}\}[\t ]*[\r\n](\*|:|\{\{col\-end)/gi, '$1');
// s = s.replace(/\{\{col\-[23]\}\}[\t ]*[\r\n](\*|:|\{\{col\-end)/gi, '$1');
// s = s.replace(/\{\{col\-[23]\}\}[\t ]*[\r\n](\*|:|\{\{col\-end)/gi, '$1');
// s = s.replace(/([\r\n](?:\*|:)[^\r\n]*[\r\n])\{\{col\-end\}\}/gi, '$1{' + '{colend}' + '}');
//}
s = s.replace(/[\r\n]\|\-[\t ]*([\r\n]\|\-)/g, '$1');
s = s.replace(/([\r\n]\|\-)[\t ]*![\t ]*/g, '$1 ');
s = s.replace(/(\{\{)[_ ]*(PAGENAME)/g, '$1subst:$2');
s = s.replace(/(\{\{)[_ ]*(#invoke:[Ss]tring)/g, '$1subst:$2');
s = s.replace(/(\{\{)[_ ]*(#expr:[ ]*\{\{subst:)/g, '$1subst:$2');
s = s.replace(/(==[ ]*Results?[ ]*)S(ummary)/g, '$1s$2');
s = s.replace(/(by[ ]*)R(ound)/g, '$1r$2');
s = s.replace(/(by[ ]*)M(atch)/g, '$1m$2');
s = s.replace(/(\{\{)[_ ]*fb[_ ]+rbr[_ ]+footer/gi, '|}$1fb rs footer');
s = s.replace(/[\r\n]*[\t ]*\|\|*(?:[ ]*rowspan[ ]*=[" ]*[0-9]+[" ]*|[\t ])*style="background-color:#F9F9F9[; ]*"[ ]*\|[\t ]*[\r\n]/g, '\n');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+r2[_ ]+header[^{}]*\|)Bury(\]\])/g, '$1BRY$2');
// s = s.replace(/([\r\n]\|\-[^\r\n]*)([\r\n])![\s]*((?:bgcolor|style)[^\|]*)\|([^\r\n]*[\r\n])![\s]*\3[\s]*\|/gi, '$1 $3$2| $4<!-- FB RM COLOR -->| ');
s = s.replace(/\{\|[\s]*class[\s]*=["\s]*wikitable["\s]*style[\s]*=["\s]*(?:text\-align:[\s]*center[;\s]*|)margin[^;"]*auto[;\s]*(?:width[\s]*:[\s0-9px%]*[;\s]*|)(?:width[\s]*=[\s]*[0-9]+|[;\s"])*[\r\n](?:\|\-[^\r\n]*[\r\n]|)(?:!|\|)(?:<[^<>]*br[^<>]*>|[\s])*(?:'''|[\s])*([^\r\n]*?)(?:'''|[\s])*[\r\n]\|\-[^\r\n]*[\r\n](?:!|\|)[\s]*\{\{flagicon\|([^{}\|]*)\|[ ]*size=[^{}\|]*\}\}[\s]*[\r\n]\|\-[^\r\n]*[\r\n](?:!|\|)(?:align[\s]*=[\s"]*center[\s"]*\||[' ])*(\[\[[^\[\]]*\]\])*[' ]*(?:<[^<>]*br[^<>]*>|[\s])*[' ]*([A-Z0-9a-z]+) [Tt]itle[' ]*(?:[\r\n]\|\-[^\r\n]*|)[\r\n]\|\}/gi, '{'+'{winners-other|$1|$2|$3|$4}'+'}');
s = s.replace(/\{\|[\s]*class[\s]*=["\s]*wikitable["\s]*style[\s]*=["\s]*(?:text\-align:[\s]*center[;\s]*|)margin[^;"]*auto[;\s]*(?:width[\s]*:[\s0-9px%]*[;\s]*|)[;\s"]*[\r\n](?:\|\-[^\r\n]*[\r\n]|)(?:!|\|)(?:<[^<>]*br[^<>]*>|[\s])*(?:'''|[\s])*([^\r\n]*?)(?:'''|[\s])*[\r\n]\|\-[^\r\n]*[\r\n](?:!|\|)(?:align[\s]*=[\s"]*center[\s"]*\||[' ])*(\[\[[^\[\]]*\]\])*[' ]*(?:<[^<>]*br[^<>]*>|[\s])*[\r\n]\|\-[^\r\n]*[\r\n]\|[' ]*([A-Z0-9a-z]+) title[' ]*(?:[\r\n]\|\-[^\r\n]*|)[\r\n]\|\}/gi, '{'+'{winners||$1|$2|$3}'+'}');
s = s.replace(/\{\|[\s]*class[\s]*=["\s]*wikitable["\s]*style[\s]*=["\s]*(?:text\-align:[\s]*center[;\s]*|)margin[^;"]*auto[;\s]*(?:width[\s]*:[\s0-9px%]*[;\s]*|)[;\s"]*[\r\n](?:\|\-[^\r\n]*[\r\n]|)(?:!|\|)(?:<[^<>]*br[^<>]*>|[\s])*(?:'''|[\s])*([^\r\n]*?)(?:'''|[\s])*[\r\n]\|\-[^\r\n]*[\r\n](?:!|\|)(?:align[\s]*=[\s"]*center[\s"]*\||[' ])*(\[\[[^\[\]]*\]\])*[' ]*(?:<[^<>]*br[^<>]*>|[\s])+[' ]*([A-Z0-9a-z]+) title[' ]*(?:[\r\n]\|\-[^\r\n]*|)[\r\n]\|\}/gi, '{'+'{winners||$1|$2|$3}'+'}');
s = s.replace(/\{\|[\s]*class[\s]*=["\s]*wikitable["\s]*style[\s]*=["\s]*(?:text\-align:[\s]*center[;\s]*|)margin[^;"]*auto[;\s]*(?:width[\s]*:[\s0-9px%]*[;\s]*|)[;\s"]*[\r\n](?:\|\-[^\r\n]*[\r\n]|)(?:!|\|[\t ]*\'\'\')((?:[^{}\[\]\|\r\n]|\{\{[^{}]*\}\}|\[\[[^\[\]]*\]\])*?)(?:\'\'\'|[\t ])*[\r\n]\|\-[^\r\n]*[\r\n]\|((?:[^{}\[\]\|\r\n]|\{\{[^{}]*\}\}|\[\[[^\[\]]*\]\])*)[\r\n]\|\}/gi, '{' + '{winners||$1|$2}' + '}');
s = s.replace(/\{\|[\s]*class[\s]*=["\s]*wikitable["\s]*style[\s]*=["\s]*(?:text\-align:[\s]*center[;\s]*|)margin[^;"]*auto[;\s]*(?:width[\s]*:[\s0-9px%]*[;\s]*|)[;\s"]*[\r\n](?:\|\-[^\r\n]*[\r\n]|)(?:!|\|[\t ]*\'\'\')((?:[^{}\[\]\|\r\n]|\{\{[^{}]*\}\}|\[\[[^\[\]]*\]\])*?)(?:\'\'\'|[\t ])*[\r\n]\|\-[^\r\n]*[\r\n]\|((?:[^{}\[\]\|\r\n]|\{\{[^{}]*\}\}|\[\[[^\[\]]*\]\])*)[\r\n]\|\-[^\r\n]*[\r\n]\|((?:[^{}\[\]\|\r\n]|\{\{[^{}]*\}\}|\[\[[^\[\]]*\]\])*)[\r\n]\|\}/gi, '{' + '{winners||$1|$2|$3}' + '}');
s = s.replace(/\{\|[^\r\n]*[\r\n]\|\-[^\r\n]*[\r\n]\|[ ]*\{\{nowrap\|Home ╲ Away\}\}[ ]*([^\r\n]*)/g, '{'+'{fb r2 header|nt=12|$1}'+'}');
lt='';
while (s != lt) {
lt = s;
s = s.replace(/(\{\{winners[^{}]*)'''/gi, '$1');
s = s.replace(/(\{\{winners[^{}]*)<[\/\s]*br[\/\s]*>[\s]*(\||\}\})/gi, '$1$2');
s = s.replace(/(\{\{winners[\s]*\|[\s]*\|(?:[^{}\[\]\|\r\n]|\{\{[^{}]*\}\}|\[\[[^\[\]]*\]\])*)<[\/\s]*br[\/\s]*>((?:[^{}\[\]\|\r\n]|\{\{[^{}]*\}\}|\[\[[^\[\]]*\]\])*\}\})/gi, '$1|$2');
s = s.replace(/(\{\{winners[^{}]*)[\s]*<[\/\s]*br[\/\s]*>[\s]*([A-Za-z0-9]+)[\s]*title[\s]*(\}\})/gi, '$1|$2$3');
s = s.replace(/([\r\n!]![^\|\r\n]*\|(?:Pos|Team|P|Pld|W|D|L|F|A|GF|GA|GD|Pts|Notes|)[ ]*)[\r\n](![^\|\r\n]*\|(?:Pos|Team|P|Pld|W|D|L|F|A|GF|GA|GD|Pts|Notes|)[ ]*(?:[\r\n]|!!))/g, '$1 !$2');
//s = s.replace(/(<!-- FB RM COLOR -->)([^\r\n]*[\r\n])![ ]*(?:bgcolor|style)[^\|]*\|[ ]*/g, '$2| $1');
//s = s.replace(/<!-- FB RM COLOR -->([^\r\n]*[\r\n](?:\|[\-\}]))/g, '$1');
s = s.replace(/(\{\{fb r2 header\|nt[ ]*=[0-9 ]*\|[^{}=]*)\|\|[ ]*width[ ]*=[0-9px ]*\|/g, '$1|');
s = s.replace(/(\{\{)[_ ]*([Ff]b[_ ]+cl2?[_ ]+team)[_ ]*(\|(?:\{\{[^{}]*\}\}|[^{}])*)(\|[ ]*wpts[ ]*=[0-9 ]*)(\||\}\})/g, '$1$2$4$3$5');
s = s.replace(/(\{\{)[_ ]*([Ff]b[_ ]+cl2?[_ ]+team)[_ ]*\|[ ]*wpts[ ]*=[ ]*2[ ]*(\|)/g, '$1$2 2pts$3');
s = s.replace(/(\{\{)[_ ]*([Ff]b[_ ]+cl2?[^\r\n]*)\|[ ]*nat[ ]*=[ ]*(\||\}\})/g, '$1$2$3');
s = s.replace(/(\{\{)[_ ]*([Ff]b[_ ]+cl2?[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*)(\|[ ]*t[ ]*=(?:\{\{[^{}]*\}\}|[^{}])*)(\|[ ]*nat[ ]*=[^\|\{\}]*)(\||\}\})/g, '$1$2$4$3$5');
s = s.replace(/(\{\{)[_ ]*([Ff]b[_ ]+cl2?[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*)\|[ ]*nat[ ]*=[ ]*([^\{\}\|]*)(\|[ ]*t[ ]*=)[ ]*/g, '$1$2$4 {'+'{flagicon|$3}'+'} ');
s = s.replace(/(\{\{)[_ ]*([Ff]b[_ ]+cl2?[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*)\|[ ]*nat[ ]*=[ ]*([^\{\}\|]*?)[ ]*\|[ ]*var[ ]*=[ ]*([0-9]+)[ ]*(\|[ ]*t[ ]*=)[ ]*/g, '$1$2$5 {'+'{flagicon|$3|$4}'+'} ');
s = s.replace(/(\{\{)[_ ]*([Ff]lagicon)[_ ]*(\|)[\s]*([^{}]*?)([\s]*)(\}\})[\t ]+/g, '$1$2$3$4$6$5 ');
}
s = s.replace(/\{\|[ ]*class="wikitable[^\r\n]*[\r\n](?:(?:!(?:[\t ]|colspan=[0-9]+[!\|]*(?:Home|Away|Total))*[\r\n])*|)(?:\|-[^\r\n]*[\r\n]|)![^\r\n]*Pos[^\r\n]*Pld[^\r\n]*W[^\r\n]*D[^\r\n]*L[^\r\n]*W[^\r\n]*D[^\r\n]*L[^\r\n]*GA[^\r\n]*Pts[^\r\n]*[\r\n]/g, '{'+'{fb ha header|sort=y|gavg=y}'+'}\n');
s = s.replace(/\{\|[ ]*class="wikitable[^\r\n]*[\r\n](?:(?:!(?:[\t ]|colspan=[0-9]+[!\|]*(?:Home|Away|Total))*[\r\n])*|)(?:\|-[^\r\n]*[\r\n]|)![^\r\n]*Pos[^\r\n]*Pld[^\r\n]*W[^\r\n]*D[^\r\n]*L[^\r\n]*W[^\r\n]*D[^\r\n]*L[^\r\n]*GD[^\r\n]*Pts[^\r\n]*[\r\n]/g, '{'+'{fb ha header|sort=y}'+'}\n');
s = s.replace(/\{\|[ ]*class="wikitable[^\r\n]*[\r\n](?:\|-[^\r\n]*[\r\n]|)![^\|\r\n]*\|[\t ]*\{\{Tooltip\|[ ]*Pos(?:[\r\n]|[^\-])*W(?:[\r\n]|[^\-])*D(?:[\r\n]|[^\-])*L(?:[\r\n]|[^\-])*([\r\n]\|\-)/g, '{'+'{fb cl header}' + '}$1');
s = s.replace(/\{\|[ ]*class="wikitable[^\r\n]*[\r\n][!\|]+[\s]*Pos[\s]*[!\|]+[\s]*Club[\s]*[!\|]+[\s]*P[\s]*[!\|]+[\s]*W[\s]*[!\|]+[\s]*D[\s]*[!\|]+[\s]*L[\s]*[!\|]+[\s]*GF[\s]*[!\|]+[\s]*GA[^\r\n]*[\r\n]/gi, '{'+'{fb cl header|sort=y}'+'}\n');
s = s.replace(/±[\t ]*0([\t ]*\|)/g, '+0$1');
s = s.replace(/–/gi, '–');
s = s.replace(/(\|[ ]*season[ ]*=[\t ]*)[\t \']*?([0-9][0-9][0-9][0-9])[\-–]([0-9][0-9]+)[\' ]*/g, '$1$2–$3');
s = s.replace(/(\|[ ]*(?:next|prev)season[ ]*=[\t ]*)[\'][\']+[\t ]*(\[\[[^\[\]]*\]\])[\t ]*[\'][\']+/g, '$1$2');
s = s.replace(/(\|[ ]*(?:next|prev)season[ ]*=[\t ]*\[\[[^\[\]\|]*\|)[\' ]*([^\|\[\]\']*)[\' ]*(\]\])/g, '$1$2$3');
s = s.replace(/(\[\[)([^\|\[\]]*) ([0-9][0-9][0-9][0-9])([\-–])([0-9][0-9]+)(#[^\|\[\]]*|)(\||\]\])/g, '$1{'+'{subst:#ifexist:$3–$5 $2|$3–$5 $2|{'+'{subst:#ifexist:$2 $3$4$5|$2 $3$4$5|$3–$5 $2}'+'}'+'}'+'}$6$7');
s = s.replace(/(\{\{[_ ]*(?:[Ss]ee[_ ]*[Aa]lso|[Dd]etails|[Mm]ain(?:[_ ]+article|))\|)([^\|\[\]]*) ([0-9][0-9][0-9][0-9])([\-–])([0-9][0-9]+)(#[^\|\[\]]*|)(\||\}\})/g, '$1{'+'{subst:#ifexist:$3–$5 $2|$3–$5 $2|{'+'{subst:#ifexist:$2 $3$4$5|$2 $3$4$5|$3–$5 $2}'+'}'+'}'+'}$6$7');
s = s.replace(/(\{\{[_ ]*(?:[Ss]ee[_ ]*[Aa]lso|[Dd]etails|[Mm]ain(?:[_ ]+article|))\|)([0-9][0-9][0-9][0-9])([\-])([0-9][0-9]+)( [^{}\|#]*)/g, '$1{'+'{subst:#ifexist:$2–$4$5|$2–$4$5|$2$3$4$5}'+'}');
s = s.replace(/(\[\[)(Russian[^\|\[\]]*) ([0-9][0-9][0-9][0-9])(#[^\|\[\]]*|)(\||\]\])/g, '$1{'+'{subst:#ifexist:$3 $2|$3 $2|$2 $3}'+'}$4$5');
s = s.replace(/(\{\{[_ ]*(?:[Ss]ee[_ ]*[Aa]lso|[Dd]etails|[Mm]ain(?:[_ ]+article|))\|)(Russian[^\|\[\]]*) ([0-9][0-9][0-9][0-9])(#[^\|\[\]\{\}]*|)(\||\}\})/g, '$1{'+'{subst:#ifexist:$3 $2|$3 $2|$2 $3}'+'}$4$5');
s = s.replace(/(\[\[)([0-9][0-9][0-9][0-9])[\-–]([0-9][0-9]+) ([^\|\[\]]*\|[^\[\]\|]*)\2[\-–]\3/g, '$1$2–$3 $4$2–$3');
s = s.replace(/(\[\[)([0-9][0-9][0-9][0-9])[\-–]([0-9][0-9]+) ([^\|\[\]]*(?:\||\]\]))/g, '$1$2–$3 $4');
// s = s.replace(/[\t ]*[\r\n]*[\t ]*[\r\n]*(\|[\t ]*match_)/g, '\n\n$1');
lt = '';
while (s != lt) {
lt = s;
s = s.replace(/(\|[\t ]*(?:match|name)_)([^=_\t ]*)((?:[\t ]*|_[^=]*)=[^\r\n]*[\r\n])[\t ]*[\r\n](\|[\t ]*match_)\2/g, '$1$2$3$4$2');
s = s.replace(/\{\{[_ ]*[Ff]b[_ ]+rbr[_ ]+t[_ ]+pos[_ ]*\|[ ]*r[ ]*=[ ]*[0-9]+[ ]*\|[ ]*tl[ ]*=[ ]*(\[\[[^\[\]]*\]\])[ ]*\|/g, '|-\n| $1 ||<!--FB FIX IT-->');
s = s.replace(/(<!--[ ]*FB FIX IT[ ]*-->)([0-9\s]*)\|/g, '|| $2 $1');
s = s.replace(/(<!--[ ]*FB FIX IT[ ]*-->)([0-9\s]*)\}\}/g, '|| $2');
s = s.replace(/(\{\{)[_ ]*[Ff]b[_ ]+r2[_ ]+header[_ ]*\|[\s]*/g, '$1fb r2 header|');
s = s.replace(/(\{\{fb r2 header\|[^{}]*)[\s]+(\||=|\}\})/g, '$1$2');
s = s.replace(/(\{\{fb r2 header\|[^{}]*(?:\||=))[\s]+/g, '$1');
}
if(0) {
lt = '';
s = s.replace(/(\{\{)(#invoke:sports table)/g, '$1§§§$2¶¶¶');
while (s != lt) {
lt = s;
s = s.replace(/(¶¶¶)((?:\{\{[^{}]*\}\}|[^{}\r\n])*)/g, '$2$1');
s = s.replace(/(¶¶¶)([\r\n]*)/g, '$2$1');
s = s.replace(/(¶¶¶)\}\}[\s]*\{\{col[\- ][^{}]*\}\}[\s]*\{\{#invoke:sports results\|main/gi, '\n|show_matches=y§§§$1');
s = s.replace(/(?:\{\{col[\- ][^{}]*\}\}|[\s])*(\{\{)§§§(#invoke:)/g, '\n$1$2');
s = s.replace(/¶¶¶(\}\})[\s]*\{\{col[\- ][^{}]*\}\}/g, '$1');
s = s.replace(/(§§§)([\s]*\|matches_style=[^\|\r\n]*[\r\n]*)/g, '$2$1');
s = s.replace(/(§§§)([\s]*\|solid_cell=[^\|\r\n]*[\r\n]*)/g, '$2$1');
s = s.replace(/(§§§)(?:[\s]*\|team[0-9]+=[^\|\r\n]*)+/g, '$1');
s = s.replace(/(\|[ ]*name_[^=]*=[^\r\n]*[\r\n])([^{}]+)(§§§)/g, '$2$1$3');
s = s.replace(/(\|[ ]*update[ ]*=[^\r\n\|\[\]]*[\r\n])((?:\{\{[^{}]*\}\}|[^{}])*[\r\n])(\|[ ]*update[ ]*=)/g, '$2$1$3');
s = s.replace(/(\|[ ]*source[ ]*=[^\r\n\|\[\]]*[\r\n])((?:\{\{[^{}]*\}\}|[^{}])*[\r\n])(\|[ ]*source[ ]*=)/g, '$2$1$3');
}
s = s.replace(/(?:§§§|¶¶¶)/g, '');
}
s = s.replace(/(\{\{)[_ ]*[Ww]futsal/g, '$1fsw');
s = s.replace(/\{\{SANFLLadderHeader[ ]*\|[ ]*year[ ]*=[ ]*(2[01][0-9][0-9]|1[89][0-9][0-9])[ ]*\}\}/g, '{' + '{#invoke:Sports table|main|style=WDL\n|title=$1 Ladder\n|section=Ladder\n|loss_before_draw=true|for_against_style=points|use_point_percentage=y\n|winpoints=2|drawpoints=1<!--CAN CHANGE VALUE OF WINS AND DRAWS FOR DIFFERENT LEAGUES:-->\n<!-- ' + 'FB VFL' + ' -->');
s = s.replace(/\{\{SANFLLadderHeader[ ]*\|[ ]*title[ ]*=[ ]*([^\|\{}]*)[ ]*\}\}/g, '{' + '{#invoke:Sports table|main|style=WDL\n|title=$1\n|section=$1\n|loss_before_draw=true|for_against_style=points|use_point_percentage=y\n|winpoints=2|drawpoints=1<!--CAN CHANGE VALUE OF WINS AND DRAWS FOR DIFFERENT LEAGUES:-->\n<!-- ' + 'FB VFL' + ' -->');
s = s.replace(/\{\{[A-Z]+LadderHeader[ ]*\|[ ]*year[ ]*=[ ]*(2[01][0-9][0-9]|1[89][0-9][0-9])[ ]*\}\}/g, '{' + '{#invoke:Sports table|main|style=WDL\n|title=$1 Ladder\n|section=Ladder\n|loss_before_draw=true|for_against_style=points|use_point_percentage=y\n|winpoints=4|drawpoints=2<!--CAN CHANGE VALUE OF WINS AND DRAWS FOR DIFFERENT LEAGUES:-->\n<!-- ' + 'FB VFL' + ' -->');
s = s.replace(/\{\{[A-Z]+LadderHeader[ ]*\|[ ]*title[ ]*=[ ]*([^\|\{}]*)[ ]*\}\}/g, '{' + '{#invoke:Sports table|main|style=WDL\n|title=$1\n|section=$1\n|loss_before_draw=true|for_against_style=points|use_point_percentage=y\n|winpoints=4|drawpoints=2<!--CAN CHANGE VALUE OF WINS AND DRAWS FOR DIFFERENT LEAGUES:-->\n<!-- ' + 'FB VFL' + ' -->');
if(s.search(/<!--[ ]*FB VFL[ ]*-->/g) >= 0) {
if(s.search(/[0-9][0-9][0-9]\.[0-9%]*[ ]*\|[ ]*[0-9]+[ ]*(?:\||\}\})/g) >=0 ) {
s = s.replace(/(\|[ ]*use_)point(_percentage)/g, '$1goal$2');
}
lt = '';
while (s != lt) {
lt = s;
var b = s.match(/\|winpoints[ ]*=[ ]*([0-9]+)[ ]*\|drawpoints[ ]*=[ ]*([0-9]+)/);
if (b) {
} else {
b = ['0', '4', '2']
}
s = s.replace(/(\{\{AFLLadderLine\|)([0-9]+)((?:\{\{[^{}]*\}\}|[^{}])*)\|(?:|[ ]*bkg[ ]*=)[ ]*(#[A-F0-9a-f]*)[; ]*(\}\})/g, '$1$2$3$5\n|col_Q=$4|text_Q=\n|result$2=Q');
s = s.replace(/(<!--[ ]*FB VFL[ ]*-->)[\r\n\t ]*\{\{AFLLadderLine\|[ ]*([0-9]+)[ ]*\|[ ]*\{\{([A-Z]+)[\t ]+([^\t {}][^{}]*[^\t {}])[\t ]*(\}\}[^\|]*)\|[ ]*[0-9]+[ ]*\|[ ]*([0-9]+)[ ]*\|[ ]*([0-9]+)[ ]*\|[ ]*([0-9]+)[ ]*\|[ ]*([0-9]+)[ ]*\|[ ]*([0-9]+)[ ]*\|[ ]*[0-9\.%]+[ ]*\|[ ]*([0-9]+)[ ]*\}\}/g, '\n|team$2=$4|name_$4={'+'{$3 $4$5|win_$4=$6|loss_$4=$7|draw_$4=$8|pf_$4=$9|pa_$4=$10|adjust_points_$4={'+'{subst:#expr:$11 - ' + b[1] + '*$6 - ' + b[2] + '*$8}'+'}$1');
s = s.replace(/(<!--[ ]*FB VFL[ ]*-->)[\r\n\t ]*\{\{AFLLadderLine\|[ ]*([0-9]+)[ ]*\|[ ]*(\[\[)([^\[\]]*\]\])([^\|]*)\|[ ]*[0-9]+[ ]*\|[ ]*([0-9]+)[ ]*\|[ ]*([0-9]+)[ ]*\|[ ]*([0-9]+)[ ]*\|[ ]*([0-9]+)[ ]*\|[ ]*([0-9]+)[ ]*\|[ ]*[0-9\.%]+[ ]*\|[ ]*([0-9]+)[ ]*\}\}/g, '\n|team$2=$2|name_$2=$3$4$5|win_$2=$6|loss_$2=$7|draw_$2=$8|pf_$2=$9|pa_$2=$10|adjust_points_$2={'+'{subst:#expr:$11 - ' + b[1] + '*$6 - ' + b[2] + '*$8}'+'}$1');
s = s.replace(/(<!--[ ]*FB VFL[ ]*-->)[\t\r\n ]*(\|col_[^\r\n]*|\|result[0-9]+[^\r\n]*)/g, '\n$2$1');
s = s.replace(/<!--[ ]*FB VFL[ ]*-->[\r\n\t ]*\{\{[A-Z]+LadderFooter[ ]*(?:|\|[ ]*year[ ]*=[ ]*[0-9]+)[ ]*\}\}/g, '\n|status_text_P=Premiers\n\n<!--CLASSIFICATION RULES-->\n|class_rules = 1) points; 2) percentage; 3) number of points for.\n\n|update=complete\n|source=\n}'+'}');
s = s.replace(/(\|name)(_[^=]*=)([ ]*\{\{[^{}]*\}\})[ ]*\(P\)/g, '$1$2$3|status$2P');
var a = s.match(/\{\{subst:#expr:[ ]*([0-9]+)[ ]*\-[ ]*([0-9]+)\*([0-9]+)[ ]*\-[ ]*([0-9]+)\*([0-9]+)[ ]*\}\}/);
if (a) {
var ap = Number(a[1]) - Number(a[2])*Number(a[3]) - Number(a[4])*Number(a[5]);
var rexp = new RegExp('\\{\\{subst:#expr:[ ]*' + a[1] + '[ ]*\\-[ ]*' + a[2] + '[ ]*\\*[ ]*' + a[3] + '[ ]*\\-[ ]*' + a[4] + '[ ]*\\*[ ]*' + a[5] + '[ ]*\\}\\}');
s = s.replace(rexp, ap);
}
s = s.replace(/\|[ ]*adjust_points_[^=]*=[ ]*0([^0-9\.,])/g, '$1');
s = s.replace(/(\|[ ]*col_[^\r\n]*)([\r\n])(\|(?:status_|team[0-9]+)[^\r\n]*)/g, '$3$2$1');
s = s.replace(/(\|[ ]*result[0-9]+[^\r\n]*)([\r\n])(\|(?:status_|team[0-9]+)[^\r\n]*)/g, '$3$2$1');
s = s.replace(/(\|col_Q[^\r\n]*)([\r\n]\|result[0-9]+[^\r\n]*)[\r\n]\1/g, '$1$2');
s = s.replace(/(\|result[0-9]+[ ]*=[^\r\n]*)[\r\n](\|result[0-9]+[ ]*=)/g, '$1$2');
}
s = s.replace(/(<noinclude>[^<>]*)<noinclude>/g, '$1');
s = s.replace(/(=[ ]*)(\[\[[0-9]+ [WANV]+FL season)((?:\{\{[^{}]*\}\}|[^{}])*\|[ ]*text_Q[ ]*=)[ ]*([\r\n])/g, '$1$2$3$2#Finals series|Finals series]]$4');
s = s.replace(/(\|[ ]*status_[^=\|\r\n]*=[^\|\r\n]*)(\|[ ]*win_[^\r\n\|=]*=[^\r\n]*)/g, '$2$1');
s = s.replace(/(\|[ ]*(?:name_|win_))/g, '\n$1');
lt = '';
while (s != lt) {
lt = s;
s = s.replace(/(\|[ ]*name_[^\r\n]*)([\r\n])(\|[ ]*(?:team[0-9]+|win_)[^\r\n]*)/g, '$3$2$1');
s = s.replace(/(\|[ ]*(?:name_|win_)[^\r\n]*)([\r\n])(\|[ ]*team[0-9]+[^\r\n]*)/g, '$3$2$1');
}
}
if (mw.config.get('wgNamespaceNumber') == 10) {
if(s.search(/<!-- EXPANDED FIXTURES -->[\t ]*[\r\n]/g) >= 0 && s.search(/\{\{#invoke:sports results/g) >= 0) {
s = s.replace(/<!-- EXPANDED FIXTURES -->[\t ]*[\r\n]/g, '');
s = s.replace(/(\|[ ]*)(res_col_header[ ]*=)/g, '$1only_pld_pts = {'+'{#if:{{'+'{expanded<includeonly>|</includeonly>}'+'}}|no|yes}'+'}\n$1show_matches = {'+'{#if:{{'+'{fixtures<includeonly>|</includeonly>}'+'}}|yes}' + '}\n$1$2');
s = s.replace(/\|[\t ]*update[ ]*=[ ]*complete[ ]*\|[ ]*source[ ]*=[ ]*[\r\n]\}\}[\t ]*[\r\n]\{\{#invoke:sports[ ]*results\|main[ ]*/g, '');
s = s.replace(/\|[ ]*solid_cell[ ]*=[ ]*grey[\t ]*(?:[\r\n]\|team[^\r\n]*)*/g, '');
s = s.replace(/\|[ ]*name_([^=]*)=[^\r\n]*\1[^\r\n]*[\r\n](\|[ ]*match_)/g, '$2');
s = s.replace(/(\|[ ]*name_)([^=]*=[\t ]*\{\{fb[wu]?)(\|[^\{\}]*\}\})/g, '$1$2$3|short_$2icon$3');
}
//if(s.search(/\|[ ]*show_limit[ ]*=/g) < 0) {
// s = s.replace(/(\|[ ]*)(res_col_header[ ]*=)/g, '$1show_limit = 5\n$1$2');
//}
if(s.search(/\[\[Category:/gi) < 0) {
s = s.replace(/(\{\{#invoke:(?:[^{}]|[\r\n]|\{\{[^{}]*\}\})*\}\})/, '$1<noinclude>\n['+'[Category:Association football standings templates]'+']\n</noinclude>');
}
}
var a = s.match(/\{\{subst:#expr:[ ]*([0-9]+)[ ]*\+[ ]*([0-9]+)[ ]*\}\}/);
if (a) {
var ap = Number(a[1]) + Number(a[2]);
var rexp = new RegExp('\\{\\{subst:#expr:[ ]*' + a[1] + '[ ]*\\+[ ]*' + a[2] + '[ ]*\\}\\}');
s = s.replace(rexp, ap);
}
a = s.match(/\{\{subst:#expr:[ ]*\-([0-9]+)[ ]*\+[ ]*([0-9]+)[ ]*\}\}/);
if (a) {
var ap = -Number(a[1]) + Number(a[2]);
var rexp = new RegExp('\\{\\{subst:#expr:[ ]*\\-' + a[1] + '[ ]*\\+[ ]*' + a[2] + '[ ]*\\}\\}');
s = s.replace(rexp, ap);
}
s = s.replace(/\[\[(?:[Ff][Ii][Ll][Ee]|[Ii][Mm][Aa][Gg][Ee])[_ ]*:[_ ]*[Gg]old[_ ]medal[_ ]icon\.svg\]\]/, '{' + '{gold1}' + '}');
s = s.replace(/\[\[(?:[Ff][Ii][Ll][Ee]|[Ii][Mm][Aa][Gg][Ee])[_ ]*:[_ ]*[Ss]ilver[_ ]medal[_ ]icon\.svg\]\]/, '{' + '{silver2}' + '}');
s = s.replace(/\[\[(?:[Ff][Ii][Ll][Ee]|[Ii][Mm][Aa][Gg][Ee])[_ ]*:[_ ]*[Bb]ronze[_ ]medal[_ ]icon\.svg\]\]/, '{' + '{bronze3}' + '}');
return s;
}
// -------------------------------------------------------------------------------- //
function wpFbUnpre(s)
{
// s = s.replace(/([\r\n])[\t ]*([^\r\n\{\}]*?)[\t ]+([0-9\-]+:[0-9\-]+|\-\-\-?|xxx|XXX)([\t ]+)/g, '$1{'+'{fb r2 team|t=$2}'+'}\n{'+'{fb r|s=$3}'+'}$4');
s = s.replace(/([\r\n])[\t ]*Team[\t ]+([^\t \r\n][^\t \r\n]*)([\t ]+[^\r\n]*[\r\n]\{\{fb r2 team)/g, '$1{' + '{fb r2 header|nt=1|$2}' + '}$3');
s = s.replace(/(Relegated)[\t ]*(<ref)/gi, '$1\n$2');
s = s.replace(/([\r\n])[\t ]*([^ \|\{\}\[\]\r\n][^ \|\{\}\[\]\r\n][^ \|\{\}\[\]\r\n](?: [^ \|\{\}\[\]\r\n][^ \|\{\}\[\]\r\n][^ \|\{\}\[\]\r\n])+)[\t ]*([\r\n][^\r\n\{\}]*?[\t ]+xxx)/g, '$1{'+'{fb r2 header|nt=1|$2}'+'}$3');
var lt = '';
var k = 1;
while (s != lt) {
lt = s;
s = s.replace(/(\{\{fb r|(?:gf|s|r)=[^{}]*\}\})[\t ]+([0-9\-]+:[0-9\-]+|\-\-\-?|xxx|XXX)([\t ]+|[\r\n])/g, '$1\n{' + '{fb r|s=$2}' + '}$3');
s = s.replace(/(\{\{fb r2 header\|nt=[0-9][0-9\+]*)(\|[^{}]*)(\}\})[\t ][\t ]*([^\r\n\t ][^\r\n\t ]*)/g, '$1+1$2|$4$3');
s = s.replace(/(\{\{fb r2 header|nt=[0-9\+]+\|)[\t ]*/g, '$1');
s = s.replace(/(\{\{fb r2 header|nt=[0-9\+]+\|[^{}]*)[\t ]*(\}\})/g, '$1$2');
s = s.replace(/(\{\{fb r2 header|nt=[0-9\+]+)(\|(?:[^ \|\{\}\[\]\r\n][^ \|\{\}\[\]\r\n][^ \|\{\}\[\]\r\n]\|)*)([^ \|\{\}\[\]\r\n][^ \|\{\}\[\]\r\n][^ \|\{\}\[\]\r\n])[\t ]+/g, '$1+1$2$3|');
var r2 = new RegExp('(\\{\\{fb r2 header\\|nt)='+k+'\\+1', 'g');
s = s.replace(r2, '$1='+(k+1));
k = k + 1;
}
lt = '';
while (s != lt) {
lt = s;
s = s.replace(/(\{\{fb r2 (?:header|team)[^{}]*\}\})[\t ]*([\r\n])([^\r\n\{\}]*?[\t ]+xxx[^\r\n]*)/g, '$1$2{'+'{fb r2 team|res=$3}'+'}');
}
lt = '';
while (s != lt) {
lt = s;
s = s.replace(/(\{\{fb r2 team)\|res=([^\r\n\{\}]*?)[\t ]+((?:[0-9]+\-[0-9]|xxx)[^\r\n\{\}]*)(\}\})/g, '$1|t=$2$4\n{'+'{fb r|s=$3$4');
s = s.replace(/(\{\{fb r\|s=)((?:[0-9]+\-[0-9]|xxx))[\t ]+((?:[0-9]+\-[0-9]|xxx)[^\r\n\{\}]*)(\}\})/g, '$1$2$4\n$1$3$4');
s = s.replace(/(\{\{fb r)\|s=[\t ]*(?:\-\-\-?|xxx)[\t ]*(\}\})/g, '$1|r=null$2');
s = s.replace(/(\{\{fb r)\|s=[\t ]*([0-9]+)[\t ]*[:\-][\t ]*([0-9]\}\})/g, '$1|gf=$2|ga=$3');
}
s = s.replace(/(\{\{fb r\|r=null\}\}[\t ]*[\r\n]*[\t ]*[\r\n])(\-\-|;)/g, '$1{'+'{end}'+'}\n$2');
var r = new RegExp('[\\r\\n][\\t ]*([0-9]+)[\\.\\t ]+([^\\r\\n]*[^\\r\\n0-9])[\\t ]+([0-9]+)[\\t ]+([0-9]+)[\\t ]+([0-9]+)[\\t ]+([0-9]+)[\\t ]+([0-9]+)[\\t \\-]+([0-9]+)[\\t ]+(\\-?[0-9]+)([\\t ]*\\[[^\\[\\]\\|]*\\]|)[\\t ]*([^\\[\\]0-9\\t\\r\\n ][^\\r\\n]*|)[\\r\\n]', 'g');
if(s.search(r) >= 0)
{
for(var i=0; i<2; i++) {
s = s.replace(r,'\n{{' + 'fb cl2 team|p=$1|t=$2|pld=$3|w=$4|d=$5|l=$6|gf=$7|ga=$8|pts=$9|pn=$10' + '}}\n{{' + 'fb cl3 qr|pld=0|competition=$11' + '}}\n');
}
s = s.replace(/\|[ ]*pn[ ]*=[ ]*(\}\})/g, '$1');
s = s.replace(/(\{\{(?:fb cl2 team|fb (?:ha|cl3) qr)[^{}]*pld=[^{}]*\}\}(?:[\t ]|[\r\n])*)\-[\t ]*\-[\t ]*\-[\t ]*\-[\-\t ]*/g, '$1{{' + 'fb cl break' + '}}');
s = s.replace(/([^\}\t \r\n](?:[\t ]|[\r\n])*)(\{\{fb cl2 team)/g, '$1{' + '{fb cl ' + 'header}' + '}\n$2');
s = s.replace(/(\{\{(?:fb cl2 team|fb (?:ha|cl3) qr)[^{}]*pld=[^{}]*\}\})((?:[\t ]|[\r\n])*[^\{\t \r\n])/g, '$1\n{{' + 'end' + '}}\n$2');
s = s.replace(/([\r\n])[\t ]+(\{\{fb cl)/g, '$1$2');
s = s.replace(/(\|[ ]*pn[ ]*=)[ ]*\[([^\[\]\|]*)\]/g, '$1$2');
s = s.replace(/(\{\{fb cl2 team(?:\{\{[^{}]*\}\}|[^{}])*\|[ ]*pts[ ]*=[^{}]*)(\|[ ]*pn[ ]*=[ ]*\-)([0-9]+)([ ]*\}\})/g, '$1|dp=$3$2$3$4');
s = s.replace(/(\{\{fb cl2 team(?:\{\{[^{}]*\}\}|[^{}])*\|[ ]*pts[ ]*=[^{}]*)(\|[ ]*pn[ ]*=[ ]*\+)([0-9]+)([ ]*\}\})/g, '$1|bp=$3$2$3$4');
s = s.replace(/(\{\{fb cl2 team(?:\{\{[^{}]*\}\}|[^{}])*\|[ ]*pts[ ]*=[^{}]*)(\|[ ]*pn[ ]*=[ ]*)([0-9]+)([ ]*(?:pts\.?|points)[ ]+deducted[ ]*\}\})/g, '$1|dp=$3$2$3$4');
s = s.replace(/(\{\{fb cl2 team(?:\{\{[^{}]*\}\}|[^{}])*\|[ ]*pts[ ]*=[^{}]*)(\|[ ]*pn[ ]*=[ ]*)([0-9]+)([ ]*bonus[ ]*(?:pts\.?|points)[ ]*\}\})/g, '$1|bp=$3$2$3$4');
s = s.replace(/(\{\{fb cl2 team(?:\{\{[^{}]*\}\}|[^{}])*)\|[ ]*pts[ ]*=[ ]*\-?[0-9]+/g, '$1');
s = s.replace(/(\{\{(?:fb (?:ha|cl3) qr|fb cl2 team)[^{}]*)\|[ ]*pld[ ]*=[ ]*[0-9]+/g, '$1');
s = s.replace(/\{\{fb (?:ha|cl3) qr\|competition=[\t ]*\}\}[\t ]*[\r\n]*/g, '');
}
s = s.replace(/(\{\{end\}\})[\t \r\n]*(<ref)/gi, '$1$2');
var pagename = mw.config.get('wgPageName');
if (pagename.search(/^199/) < 0 && pagename.search(/^20/) < 0) {
// s = s.replace(/fb cl2 team(\|p=)/g, 'fb cl2 team|wpts=2$1');
}
return s;
}
// -------------------------------------------------------------------------------- //
function wpFbUntable(s)
{
s = s.replace(/\{\|[\t ]*class="wikitable"[\t ]*style="text-align:[\t ]*center[;\t ]*"[\t ]*[\r\n]\|[ ]*Pos[ ]*\|\|[ ]*Club[ ]*[\r\n]\|P\|\|W\|\|D\|\|L\|\|GF\|\|GA\|\|GD\|\|Pts[ ]*[\r\n]\|[ ]*Notes[ ]*[\r\n]/g, '{' + '{fb cl header|t-width=auto}' + '}\n');
s = s.replace(/\{\|[\t ]*class="wikitable"[\t ]*style="text-align:[\t ]*center[;\t ]*"[\t ]*[\r\n]\|[ ]*Pos[ ]*\|\|[ ]*Club[ ]*[\r\n]\|P\|\|W\|\|D\|\|L\|\|GF\|\|GA\|\|GD\|\|Pts[ ]*[\r\n]/g, '{' + '{fb cl header|noqr=y|t-width=auto}' + '}\n');
s = s.replace(/(\{\{fb cl2 header[^{}]*)\|[ ]*noqr[ ]*=[yn ]*(\||\}\})/g, '$1$2');
s = s.replace(/(\{\{fb cl2? header[^{}]*\}\})[\t ]*!![^\r\n]*/g, '$1');
s = s.replace(/([\r\n])(\|[ ]*align[ ]*=[" ]*left[" ]*\|)[ ]*([0-9]+\.)[ ]*/g, '$1|$3|$2 ');
s = s.replace(/−/g, '–');
// s = s.replace(/[\r\n]\|[\t ]*([\r\n]\|(?:\}|\-))/g, '$1');
if(s.search(/\[\[(?:File|Image)[\t ]*:[\t ]*(?:1uparrow[_ ]+green\.svg|1downarrow[_ ]+red.svg)/gi) >= 0) {
s = s.replace(/[\r\n]\|\|?[\t ]*(\[\[(?:File|Image)[\t ]*:[\t ]*(?:1uparrow[_ ]+green\.svg|1downarrow[_ ]+red.svg)[^\[\]]*\]\]|)[\t ]*\|(\|[\t ]*[0-9]+[\. ]*\|\|[\t ]*(?:[^\r\n\|\[\]]|\[\[[^\[\]]*\]\])*)/g, '\n$2 $1');
s = s.replace(/[\t ]*\[\[(?:File|Image)[\t ]*:[\t ]*1uparrow[_ ]+green\.svg[^\[\]]*\]\]/gi, ' (P)');
s = s.replace(/[\t ]*\[\[(?:File|Image)[\t ]*:[\t ]*1downarrow[_ ]+red\.svg[^\[\]]*\]\]/gi, ' (R)');
}
//s = s.replace(/(?:ff1515|FF3c3c|FF0000)/gi, 'FFCCCC');
//s = s.replace(/FF7F00/gi, 'D0F0C0');
var posres = 'pos';
var legendpos = 'br';
if (s.search(/\|[\t ]*[WDL][\t ]*(?:[\r\n]|\|\|)/g) >= 0) {
posres = 'res';
legendpos = 'b';
}
function myRowClean(ss) {
ss = ss.replace(/(<!-- [A-Z]+ FB UNSUBST:[^<>]*-->[\t ]*[\r\n])[\t ]*[\r\n]/g, '$1');
ss = ss.replace(/(<!-- [A-Z]+ FB UNSUBST:[^<>]*-->)[\t ]*\|\|*/g, '$1\n|');
ss = ss.replace(/(<!-- [A-Z]+ FB UNSUBST:[^<>]*-->[\r\n])\|[\t ]*(\|\||[\r\n][\t ]*\|)/g, '$1|–$2');
ss = ss.replace(/(<!-- [A-Z]+ FB UNSUBST:[^<>]*-->)[\t ]*[\r\n][!\|](?:[\t ]*rowspan[\t ]*=[" ]*2[" ]*\||[\t ]*style[\t ]*=[\t "]*text-align[\t ]*:[\t ]*(?:left|center)[;\t "]*\||[\t ]*v?align[\t ]*=[" ]*(?:left|center|right|top)[" ]*\||[\t ]*\|)/gi, '$1\n|');
ss = ss.replace(/(<!-- [A-Z]+ FB UNSUBST:[^<>]*-->[\r\n])![\t ]*([0-9])/g, '$1|$2');
return ss
}
var lt='';
var k=0;
while(lt != s && k < 100) {
lt = s;
s = s.replace(/(\{\{)[_ ]*[Ff]b[_ ]+rbr[_ ]+pos[_ ]+header[^{}]*sort[^{}]*\}\}[\t ]*(?:[\r\n][\t ]*|)[\r\n]\|\-[^\r\n]*[\r\n]\|(?:[\t ]*v?align[\t ]*=[\t "]*[a-z]+[\t "]*\||[\t ]*style[\t ]*=[\t "]*text-align[\t ]*:[\t ]*(?:left|center)[;\t "]*\||)[\t ]*((?:\{\{flagicon[^{}]*\}\}[\t ]*|)\[\[[^\[\]]*\]\]|[^\[\]\|\r\n]*)[\t ]*([\r\n]|\|\|)/gi, '$1#invoke:sports rbr table|table|sortable=y|legendpos=' + legendpos + '\n|team' + (k+1) + '=$2\n|' + posres + (k+1) + '=<!-- FB POS UNSUBST -->$3');
s = s.replace(/(\{\{)[_ ]*[Ff]b[_ ]+rbr[_ ]+pos[_ ]+header[^{}]*\}\}[\t ]*(?:[\r\n][\t ]*|)[\r\n]\|\-[^\r\n]*[\r\n]\|(?:[\t ]*v?align[\t ]*=[\t "]*[a-z]+[\t "]*\||[\t ]*style[\t ]*=[\t "]*text-align[\t ]*:[\t ]*(?:left|center)[;\t "]*\||)[\t ]*(\[\[[^\[\]]*\]\]|[^\[\]\|\r\n]*)[\t ]*([\r\n]|\|\|)/gi, '$1#invoke:sports rbr table|table|legendpos=' + legendpos + '\n|team' + (k+1) + '=$2\n|' + posres + (k+1) + '=<!-- FB POS UNSUBST -->$3');
s = s.replace(/<!-- FB RBR UNSUBST -->[\t ]*[\r\n]*\|\-[^\r\n]*[\r\n]\|(?:[\t ]*v?align[\t ]*=[\t "]*[a-z]+[\t "]*\||[\t ]*style[\t ]*=[\t "]*text-align[\t ]*:[\t ]*(?:left|center)[;\t "]*\||)[\t ]*((?:\{\{flagicon[^{}]*\}\}[\t ]*|)\[\[[^\[\]]*\]\]|[^\[\]\|\r\n]*)[\t ]*([\r\n]|\|\|)/g, '\n|team' + (k+1) + '=$1\n|' + posres + (k+1) + '=<!-- FB POS UNSUBST -->$2');
if (s.search(/FB POS UNSUBST/g) >= 0) {
for (var kp=0; kp<100; kp++) {
s = s.replace(/(<!-- FB POS UNSUBST -->)[\t ]*[\r\n]\|*([^\|\-\}])/g, '$1||$2');
s = s.replace(/(<!-- FB POS UNSUBST -->[\t ]*\|\|)[\t ]*bgcolor=#bbf3bb[\t ]*\|[\t ]*([A-Z0-9][A-Z0-9][A-Z0-9])[\t ]*(\||[\r\n])/g, '$1W<sup>$2</sup>$3');
s = s.replace(/(<!-- FB POS UNSUBST -->[\t ]*\|\|)[\t ]*bgcolor=#ffffbb[\t ]*\|[\t ]*([A-Z0-9][A-Z0-9][A-Z0-9])[\t ]*(\||[\r\n])/g, '$1D<sup>$2</sup>$3');
s = s.replace(/(<!-- FB POS UNSUBST -->[\t ]*\|\|)[\t ]*bgcolor=#ffbbbb[\t ]*\|[\t ]*([A-Z0-9][A-Z0-9][A-Z0-9])[\t ]*(\||[\r\n])/g, '$1L<sup>$2</sup>$3');
s = s.replace(/(<!-- FB POS UNSUBST -->)[\t ]*\|\|([\t ]*style[\t ]*=[^\|]*\||[\t ]*bgcolor[^\|]*\||)[\t \']*([HAWDL0-9PBC=]*(?:<sup>[^<>]*<\/sup>|))[\t \']*(\|\||[\r\n])/g, '<!-- FB STYLE $2 -->$3/$1$4');
s = s.replace(/(<!-- FB POS UNSUBST -->)[\t ]*\|\|[\t \']*(\[\[[^\|\[\]]*\|[HA]\]\])[\t \']*(\|\||[\r\n])/g, '$2/$1$3');
}
s = s.replace(/\/[\t ]*<!-- FB POS UNSUBST -->[\t ]*\|\|\|?[\t ]*([\r\n]\|\-|[\r\n]\|\})/g, '/<!-- FB RBR UNSUBST -->$1');
s = s.replace(/\/[\t ]*<!-- FB POS UNSUBST -->([\r\n]\|\-|[\r\n]\|\})/g, '<!-- FB RBR UNSUBST -->$1');
s = s.replace(/<!-- FB POS UNSUBST -->[\t ]*\|\|\|?[\t ]*([\r\n]\|\-|[\r\n]\|\})/g, '/<!-- FB RBR UNSUBST -->$1');
s = s.replace(/<!-- FB POS UNSUBST -->([\r\n]\|\-|[\r\n]\|\})/g, '<!-- FB RBR UNSUBST -->$1');
s = s.replace(/<!-- FB RBR UNSUBST -->[\t ]*[\r\n]\|\-[^\r\n]*[\r\n]\|\}/g, '\n<!-- FB RBR FOOTER -->}}');
s = s.replace(/<!-- FB RBR UNSUBST -->[\t ]*[\r\n]\|\}/g, '\n<!-- FB RBR FOOTER -->}}');
}
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+ha[_ ]*(?:qr|team|header|hth)(?:[^{}]|\{\{[^{}]*\}\})*\}\})[\t ]*(?:[\r\n][\t ]*|)([\r\n])\|\-[ ]*bgcolor[\t ]*=[\t "]*([^"\|\[\]\{\}\r\n]*)[\t "]*([\r\n])/gi, '$1$2<!-- HAP FB UNSUBST: bc=$3 -->$4');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+ha[_ ]*(?:qr|team|header|hth)(?:[^{}]|\{\{[^{}]*\}\})*\}\})[\t ]*(?:[\r\n][\t ]*|)([\r\n])\|\-[ ]*style[\t ]*=[\t "]*(?:vertical-align:top;[\t ]*|text-align:left;[\t ]*)*(?:background:[\t ]*|background\-color:[\t ]*)([^"\|\[\]\{\}\r\n;]*)[\t; "]*([\r\n])/gi, '$1$2<!-- HAP FB UNSUBST: bc=$3 -->$4');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+ha[_ ]*(?:qr|team|header|hth)(?:[^{}]|\{\{[^{}]*\}\})*\}\})[\t ]*(?:[\r\n][\t ]*|)([\r\n])\|\-[ ]*([\r\n])/gi, '$1$2<!-- HAP FB UNSUBST: -->$3');
s = s.replace(/(<!-- HAP FB UNSUBST:[^<>]*-->[\t ]*[\r\n]\|)\|/g, '$1');
s = s.replace(/<!-- HAP FB UNSUBST:[^<>]*-->[\t ]*[\r\n](\|\})/g, '$1');
s = myRowClean(s);
s = s.replace(/(<!-- )HAP( FB UNSUBST:[^<>]*-->)[\t ]*[\r\n]\|[\t \']*([0-9]+)\.?[\t \']*([\r\n\t ]*\|)/g, '{' + '{FB HA TEAM|p=$3$1HAT$2$4');
s = s.replace(/(<!-- )HAP( FB UNSUBST:[^<>]*-->)[\t ]*[\r\n]\|[\t \']*((?:\{\{[^{}]*\}\}|[^\[\]\{\}\|\r\n=\']|\'\'\'(?: |[\t ])*\'\'\'|\[\[[^\[\]]*\]\])*)[\t \']*(<ref[^<>\/]*>[^<>]*<\/ref>|)([\r\n\t ]*\|)/g, '{' + '{FB HA TEAM|t=$3$4$1HAN$2$5');
s = myRowClean(s);
s = s.replace(/(<!-- )HAT( FB UNSUBST:[^<>]*-->)[\t ]*[\r\n]\|[\t \']*((?:\{\{[^{}]*\}\}|[^\[\]\{\}\|\r\n=\']|\'\'\'(?: |[\t ])*\'\'\'|\[\[[^\[\]]*\]\])*)[\t \']*((?:<ref[^<>\/]*>[^<>]*<\/ref>|<ref[^<>\/]*\/>|\'*\([A-Z\.]*\)\'*|[\t ])*)([\r\n\t ]*\|)/g, '|t=$3$4$1HAN$2$5');
s = myRowClean(s);
s = s.replace(/(<!-- )HAN( FB UNSUBST:[^<>]*-->)[\t ]*[\r\n]\|[\t \']*([0-9]+)[\t \']*([\r\n\t ]*\|)/g, '$1HW$2$4');
s = myRowClean(s);
s = s.replace(/(<!-- )HW( FB UNSUBST:[^<>]*-->)[\t ]*[\r\n]\|[\t \']*([0-9]+)[\t \']*([\r\n\t ]*\|)/g, '|hw=$3$1HD$2$4');
s = myRowClean(s);
s = s.replace(/(<!-- )HD( FB UNSUBST:[^<>]*-->)[\t ]*[\r\n]\|[\t \']*([0-9]+)[\t \']*([\r\n\t ]*\|)/g, '|hd=$3$1HL$2$4');
s = myRowClean(s);
s = s.replace(/(<!-- )HL( FB UNSUBST:[^<>]*-->)[\t ]*[\r\n]\|[\t \']*([0-9]+)[\t \']*([\r\n\t ]*\|)/g, '|hl=$3$1HGF$2$4');
s = myRowClean(s);
s = s.replace(/(<!-- )HGF( FB UNSUBST:[^<>]*-->)[\t ]*[\r\n]\|[\t \']*([0-9]+)[\t \']*([\r\n\t ]*\|)/g, '|hgf=$3$1HGA$2$4');
s = myRowClean(s);
s = s.replace(/(<!-- )HGA( FB UNSUBST:[^<>]*-->)[\t ]*[\r\n]\|[\t \']*([0-9]+)[\t \']*([\r\n\t ]*\|)/g, '|hga=$3$1AW$2$4');
s = myRowClean(s);
s = s.replace(/(<!-- )AW( FB UNSUBST:[^<>]*-->)[\t ]*[\r\n]\|[\t \']*([0-9]+)[\t \']*([\r\n\t ]*\|)/g, '|aw=$3$1AD$2$4');
s = myRowClean(s);
s = s.replace(/(<!-- )AD( FB UNSUBST:[^<>]*-->)[\t ]*[\r\n]\|[\t \']*([0-9]+)[\t \']*([\r\n\t ]*\|)/g, '|ad=$3$1AL$2$4');
s = myRowClean(s);
s = s.replace(/(<!-- )AL( FB UNSUBST:[^<>]*-->)[\t ]*[\r\n]\|[\t \']*([0-9]+)[\t \']*([\r\n\t ]*\|)/g, '|al=$3$1AGF$2$4');
s = myRowClean(s);
s = s.replace(/(<!-- )AGF( FB UNSUBST:[^<>]*-->)[\t ]*[\r\n]\|[\t \']*([0-9]+)[\t \']*([\r\n\t ]*\|)/g, '|agf=$3$1AGA$2$4');
s = myRowClean(s);
s = s.replace(/(<!-- )AGA( FB UNSUBST:[^<>]*-->)[\t ]*[\r\n]\|[\t \']*([0-9]+)[\t \']*([\r\n\t ]*\|)/g, '|aga=$3$1HAGF$2$4');
s = myRowClean(s);
s = s.replace(/(<!-- )HAGF( FB UNSUBST:[^<>]*-->)[\t ]*[\r\n]\|[\t \']*([0-9]+)[\t \']*([\r\n\t ]*\|)/g, '$1HAGA$2$4');
s = myRowClean(s);
s = s.replace(/(<!-- )HAGA( FB UNSUBST:[^<>]*-->)[\t ]*[\r\n]\|[\t \']*([0-9]+)[\t \']*([\r\n\t ]*\|)/g, '$1HAGR$2$4');
s = myRowClean(s);
for(var hh=0; hh<2; hh++) {
s = s.replace(/(<!-- )HAG[RD]( FB UNSUBST:[^<>]*-->)[\t ]*[\r\n](?:\|[\t ]*style[^\|]*|)\|[\t \']*([0-9\.]+)[\t \']*([\r\n\t ]*\|)/g, '$1GD$2$4');
s = s.replace(/(<!-- )HAG[RD]( FB UNSUBST:[^<>]*-->)[\t ]*[\r\n](?:\|[\t ]*style[^\|]*|)\|[\t \']*([\-\+−–]?[\t ]*[0-9\.]+)[\t \']*([\r\n\t ]*\|)/g, '$1GD$2|$3$4');
ss = myRowClean(s);
}
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl[23]?[_ ]*(?:qr|team|header|hth)(?:[^{}]|\{\{[^{}]*\}\})*\}\}[\t ]*(?:[\r\n][\t ]*|[\r\n]\|\-[^\r\n]*))text\-align[ ]*:[ ]*(?:left|right|center)[; ]*/gi, '$1');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl[23]?[_ ]*(?:qr|team|header|hth)(?:[^{}]|\{\{[^{}]*\}\})*\}\}[\t ]*(?:[\r\n][\t ]*|[\r\n]\|\-[^\r\n]*))vertical\-align[ ]*:[ ]*top[; ]*/gi, '$1');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl[23]?[_ ]*(?:qr|team|header|hth)(?:[^{}]|\{\{[^{}]*\}\})*\}\}[\t ]*(?:[\r\n][\t ]*|[\r\n]\|\-[^\r\n]*))style[ ]*=[";\t ]*([\r\n])/gi, '$1$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl[23]?[_ ]*(?:qr|team|header|hth)(?:[^{}]|\{\{[^{}]*\}\})*\}\})[\t ]*(?:[\r\n][\t ]*|)([\r\n])\|\-(?:v?align[ ]*=['" ]*(?:left|right|center|top)['" ]*|[\t ])*bgcolor[\t ]*=[\t "]*([^"\|\[\]\{\}\r\n]*)[\t "]*(?:v?align[ ]*=[" ]*[a-z]+[" ]*|width[ ]*=["0-9 ]+)*([\r\n])/gi, '$1$2<!-- P FB UNSUBST: bc=$3 -->$4');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl[23]?[_ ]*(?:qr|team|header|hth)(?:[^{}]|\{\{[^{}]*\}\})*\}\})[\t ]*(?:[\r\n][\t ]*|)([\r\n])\|\-(?:v?align[ ]*=['" ]*(?:left|right|center|top)['" ]*|[\t ])*style[\t ]*=[\t "]*(?:vertical-align:top;[\t ]*|text-align:left;[\t ]*)*(?:background:[\t ]*|background\-color:[\t ]*)([^"\|\[\]\{\}\r\n;]*)[\t; "]*(?:align[ ]*=[" ]*[a-z]+[" ]*|width[ ]*=["0-9 ]+)*([\r\n])/gi, '$1$2<!-- P FB UNSUBST: bc=$3 -->$4');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl[23]?[_ ]*(?:qr|team|header|hth)(?:[^{}]|\{\{[^{}]*\}\})*\}\})[\t ]*(?:[\r\n][\t ]*|)([\r\n])\|\-(?:v?align[ ]*=['" ]*(?:left|right|center|top)['" ]*|[\t ])*([\r\n])/gi, '$1$2<!-- P FB UNSUBST: -->$3');
s = s.replace(/(<!-- P FB UNSUBST:[^<>]*-->[\t ]*[\r\n]\|)\|/g, '$1');
s = s.replace(/<!-- P FB UNSUBST:[^<>]*-->[\t ]*[\r\n](\|\})/g, '$1');
s = s.replace(/<!-- P FB UNSUBST:[^<>]*-->[\t ]*[\r\n](\{\{fb cl footer)/g, '$1');
s = myRowClean(s);
s = s.replace(/(<!-- )P( FB UNSUBST:[^<>]*-->)[\t ]*[\r\n]\|[\t \']*([=–0-9]+|\[\[#[^\[\]]*\]\]|\{\{(?:gold1|silver2|bronze3)\}\})\.?[\t \']*([\r\n\t ]*\|)/g, '{' + '{FB CL2 TEAM|p=$3$1T$2$4');
s = s.replace(/(<!-- )P( FB UNSUBST:[^<>]*-->)[\t ]*[\r\n]\|[\t \']*((?:\{\{[^{}]*\}\}|[^\[\]\{\}\|\r\n=\']|\'\'\'(?: |[\t ])*\'\'\'|\[\[[^\[\]]*\]\]|'''\([A-Z, ]+\)''')*)[\t \']*(<ref[^<>\/]*>[^<>]*<\/ref>|)([\r\n\t ]*\|)/g, '{' + '{FB CL2 TEAM|t=$3$4$1N$2$5');
s = myRowClean(s);
if (s.search(/group[ ]*=[ ]*[a-z]+/g) >= 0) {
s = s.replace(/(<!-- )T( FB UNSUBST:[^<>]*-->)[\t ]*[\r\n]\|[\t \']*((?:\{\{[^{}]*\}\}|[^\[\]\{\}\|\r\n=]|\'\'\'(?: |[\t ])*\'\'\'|\[\[[^\[\]]*\]\])*?)[\t \']*((?:<ref[^<>\/]*>[^<>]*<\/ref>|<ref[^<>\/]*\/>|\'*\([A-Z\., ]*\)\'*|[\t ])*)([\r\n\t ]*\|)/g, '|group=$3$4$1T$2$5');
s = myRowClean(s);
}
s = s.replace(/(<!-- )T( FB UNSUBST:[^<>]*-->)[\t ]*[\r\n]\|[\t \']*((?:\{\{[^{}]*\}\}|[^\[\]\{\}\|\r\n=]|\'\'\'(?: |[\t ])*\'\'\'|\[\[[^\[\]]*\]\])*?)[\t \']*((?:<ref[^<>\/]*>[^<>]*<\/ref>|<ref[^<>\/]*\/>|\'*\([A-Z\., ]*\)\'*|[\t ])*)([\r\n\t ]*\|)/g, '|t=$3$4$1N$2$5');
s = myRowClean(s);
if (s.search(/ptsfirst[ ]*=[ ]*[a-z]+/g) >= 0) {
s = s.replace(/(<!-- )N( FB UNSUBST:[^<>]*-->)[\t ]*[\r\n]\|[\t \']*([0-9–]+)[\t \']*([\r\n\t ]*\|)/g, '<!-- FB PTS $3 -->$1PT$2$4');
s = s.replace(/(<!-- )N( FB UNSUBST:[^<>]*-->)[\t ]*[\r\n]\|[\t \']*([0-9–]+)[\t \']*([\+\-][0-9]+)[\t \']*([\r\n\t ]*\|)/g, '|pn=$4<!-- FB PTS $3 -->$1PT$2$5');
s = s.replace(/(<!-- )N( FB UNSUBST:[^<>]*-->)[\t ]*[\r\n]\|[\t \']*([0-9–]+)[\t \']*<sup>([^<>]*)<\/sup>[\t \']*([\r\n\t ]*\|)/g, '|pn=$4<!-- FB PTS $3 -->$1PT$2$5');
s = s.replace(/(<!-- )N( FB UNSUBST:[^<>]*-->)[\t ]*[\r\n]\|[\t \']*([0-9–]+)[\t \']*([\*†‡]+)[\t \']*([\r\n\t ]*\|)/g, '|pn=$4<!-- FB PTS $3 -->$1PT$2$5');
s = myRowClean(s);
s = s.replace(/(<!-- )PT( FB UNSUBST:[^<>]*-->)[\t ]*[\r\n]\|[\t \']*([0-9–]+)[\t \']*([\r\n\t ]*\|)/g, '$1W$2$4');
} else {
s = s.replace(/(<!-- )N( FB UNSUBST:[^<>]*-->)[\t ]*[\r\n]\|[\t \']*([0-9–]+)[\t \']*\|\|[\t ]*\|\|[\t ]*\|\|[\t ]*\|\|[\t ]*\|\|[\t ]*\|\|[\t ]*\|(\|)/g, '|pld=$3|gf=–|ga=–$1PT$2$4');
s = s.replace(/(<!-- )N( FB UNSUBST:[^<>]*-->)[\t ]*[\r\n]\|[\t \']*([0-9–]+)[\t \']*\|\|[\t ]*\|\|[\t ]*\|\|[\t ]*\|(\|)/g, '|pld=$3$1GF$2$4');
s = s.replace(/(<!-- )N( FB UNSUBST:[^<>]*-->)[\t ]*[\r\n]\|[\t \']*([0-9–]+)[\t \']*([\r\n\t ]*\|)/g, '$1W$2$4');
}
s = s.replace(/(<!-- )N( FB UNSUBST:[^<>]*-->)[\t ]*[\r\n]*[\t ]*([\r\n]\|[\}\-])/g, '|w=–|d=–|l=–|gf=–|ga=–$1PT$2$3');
s = myRowClean(s);
s = s.replace(/(<!-- )W( FB UNSUBST:[^<>]*-->)[\t ]*[\r\n]\|[\t \']*([0-9\/–\?]+)[\t \']*([\r\n\t ]*\|)/g, '|w=$3$1D$2$4');
s = myRowClean(s);
if(s.search(/\|[ ]*OT[ ]*=[ ]*[y1]/gi) >=0) {
s = s.replace(/(<!-- )D( FB UNSUBST:[^<>]*-->)/g, '$1OTW$2');
s = myRowClean(s);
}
s = s.replace(/(<!-- )OTW( FB UNSUBST:[^<>]*-->)[\t ]*[\r\n]\|[\t \']*([0-9\/–\?]+)[\t \']*([\r\n\t ]*\|)/g, '|ow=$3$1OTL$2$4');
s = myRowClean(s);
s = s.replace(/(<!-- )OTL( FB UNSUBST:[^<>]*-->)[\t ]*[\r\n]\|[\t \']*([0-9\/–\?]+)[\t \']*([\r\n\t ]*\|)/g, '|ol=$3$1L$2$4');
s = myRowClean(s);
if(s.search(/nodraw[ ]*=[ ]*[y1]/g) >=0) {
s = s.replace(/(<!-- )D( FB UNSUBST:[^<>]*-->)/g, '$1L$2');
}
s = s.replace(/(<!-- )D( FB UNSUBST:[^<>]*-->)[\t ]*[\r\n]\|[\t \']*([0-9\/–\?]+)[\t \']*([\r\n\t ]*\|)/g, '|d=$3$1L$2$4');
s = myRowClean(s);
s = s.replace(/(<!-- )L( FB UNSUBST:[^<>]*-->)[\t ]*[\r\n]\|[\t \']*([0-9\/–\?]+)[\t \']*([\r\n\t ]*\|)/g, '|l=$3$1GF$2$4');
s = myRowClean(s);
if(s.search(/loss_before_(?:tie|draw)[ ]*=[ ]*[y1]/g) >=0) {
s = s.replace(/(\|d=)([0-9]+)(\|l=)([0-9]+)(<!-- GF)/g, '$1$4$3$2$5');
}
if(s.search(/loss_before_ot[ ]*=[ ]*[y1]/g) >=0) {
s = s.replace(/(\|ow=)([0-9]+)(\|ol=)([0-9]+)(\|l=)([0-9]+)(<!-- GF)/g, '$1$4$3$6$5$2$7');
}
s = s.replace(/(<!-- )GF( FB UNSUBST:[^<>]*-->)[\t ]*[\r\n]\|[\t \']*([0-9\/–\?]+)[\t \']*[–\-][\t \']*([0-9]+)[\t \']*([\r\n\t ]*\|)/g, '|gf=$3|ga=$4$1GD$2$5');
s = s.replace(/(<!-- )GF( FB UNSUBST:[^<>]*-->)[\t ]*[\r\n]\|[\t \']*([0-9\/–\?]+)[\t \']*([\r\n\t ]*\|)/g, '|gf=$3$1GA$2$4');
s = myRowClean(s);
s = s.replace(/(<!-- )GA( FB UNSUBST:[^<>]*-->)[\t ]*[\r\n]\|[\t \']*([0-9\/–\?]+)[\t \']*([\r\n\t ]*\|)/g, '|ga=$3$1GD$2$4');
s = myRowClean(s);
if (s.search(/[ ]*show_tries[ ]*=[ ]*[a-z]+/g) >= 0) {
s = s.replace(/(<!-- )GD( FB UNSUBST:[^<>]*-->)[\t ]*[\r\n]\|[\t \']*([\-\+−–]?[\t ]*[0-9\.–\?]+)[\t \']*([\r\n\t ]*\|)/g, '$1TF$2$4');
s = myRowClean(s);
s = s.replace(/(<!-- )TF( FB UNSUBST:[^<>]*-->)[\t ]*[\r\n]\|[\t \']*([0-9\/–\?]+)[\t \']*([\r\n\t ]*\|)/g, '|tf=$3$1PT$2$4');
s = myRowClean(s);
}
s = s.replace(/(<!-- )GD( FB UNSUBST:[^<>]*-->)[\t ]*[\r\n]\|[\t \']*([\-\+−–]?[\t ]*[0-9\.–\?]+)[\t \']*([\r\n\t ]*\|)/g, '$1PT$2$4');
s = myRowClean(s);
s = s.replace(/<!-- (?:GD|PT) FB UNSUBST:[ ]*([^<>]*) -->[\t ]*[\r\n]\|[\t \']*([0-9–\?]+)[\t \']*([\r\n\t ]*\|)/g, '<!-- FB PTS $2 -->|$1}' + '}\n$3');
s = s.replace(/<!-- (?:GD|PT) FB UNSUBST:[ ]*([^<>]*) -->[\t ]*[\r\n]\|[\t \']*([0-9–\?]+)[\t \']*([\+\-][0-9]+)[\t \']*([\r\n\t ]*\|)/g, '<!-- FB PTS $2 -->|pn=$3|$1}' + '}\n$4');
s = s.replace(/<!-- (?:GD|PT) FB UNSUBST:[ ]*([^<>]*) -->[\t ]*[\r\n]\|[\t \']*([0-9–\?]+)[\t \']*<sup>([^<>\r\n]*)<\/sup>[\t \']*([\r\n\t ]*\|)/g, '<!-- FB PTS $2 -->|pn=$3|$1}' + '}\n$4');
s = s.replace(/<!-- (?:GD|PT) FB UNSUBST:[ ]*([^<>]*) -->[\t ]*[\r\n]\|[\t \']*([0-9–\?]+)[\t \']*([\*†‡]+)[\t \']*([\r\n\t ]*\|)/g, '<!-- FB PTS $2 -->|pn=$3|$1}' + '}\n$4');
s = s.replace(/<!-- (?:GD|PT) FB UNSUBST:[ ]*([^<>]*) -->[\t ]*[\r\n]\|[\t \']*([0-9–\?]+)[\t \']*(\{\{ref[^{}]*\}\})[\t \']*([\r\n\t ]*\|)/g, '<!-- FB PTS $2 -->|pn=$3|$1}' + '}\n$4');
s = s.replace(/<!-- (?:GD|PT) FB UNSUBST:[ ]*([^<>]*) -->[\t ]*[\r\n]\|[\t \']*([0-9–\?]+)[\t \']*(<ref[^<>\/]*>[^<>]*<\/ref>|<ref[^<>]*\/>)[\t \']*([\r\n\t ]*\|)/g, '<!-- FB PTS $2 -->|pn=$3|$1}' + '}\n$4');
s = s.replace(/<!-- (?:GD|PT) FB UNSUBST:[ ]*([^<>]*) -->[\t ]*[\r\n]()([\r\n\t ]*\|)/g, '|$1}' + '}\n$3');
s = s.replace(/(\{\{[Ff]b[_ ]+(?:ha[\t ]+|cl[0-9\t ]*)team(?:\{\{[^{}]*\}\}|[^{}])*\}\})[\t \r\n]*\|[\|\t ]*([\r\n])/gi, '$1$2');
s = s.replace(/(\{\{[Ff]b[_ ]+(?:ha[\t ]+|cl[0-9\t ]*)team[^\r\n]*[\r\n][^\r\n]*)<small>/gi, '$1');
s = s.replace(/(\{\{[Ff]b[_ ]+(?:ha[\t ]+|cl[0-9\t ]*)team[^\r\n]*[\r\n][^\r\n]*)<\/small>/gi, '$1');
s = s.replace(/(\{\{[Ff]b[_ ]+(?:ha[\t ]+|cl[0-9\t ]*)team[^\r\n]*[\r\n][^\r\n]*)<[\/]*br[^<>]*>/gi, '$1 ');
s = s.replace(/(\{\{[Ff]b[_ ]+cl[0-9\t ]*team(?:\{\{[^{}]*\}\}|[^{}])*\}\}[\t \r\n]*\|\|?[\t ]*)v?align[\t ]*=["' ]*(?:left|right|center|top)["' ]*\|/gi, '$1 ');
s = s.replace(/(\{\{[Ff]b[_ ]+cl[0-9\t ]*team(?:\{\{[^{}]*\}\}|[^{}])*\}\}[\t \r\n]*\|\|?[\t ]*)v?align[\t ]*=["' ]*(?:left|right|center|top)["' ]*(rowspan)/gi, '$1$2');
s = s.replace(/(\{\{[Ff]b[_ ]+cl[0-9\t ]*team(?:\{\{[^{}]*\}\}|[^{}])*\}\})[\t \r\n]*\|\|*[^\|]*[\t ]*rowspan[\t ]*=[" ]*([0-9]+)[" ]*[^\|]*\|([^\r\n]*)/gi, '$1\n{' + '{fb cl3 qr|rows=$2|competition=$3}' + '}');
s = s.replace(/(\{\{[Ff]b[_ ]+cl[0-9\t ]*team(?:\{\{[^{}]*\}\}|[^{}])*\}\})[\t \r\n]*\|\|*([^\}\-](?:[^\r\n=]|<ref[^<>\/]*\/>|<ref[^<>]*>[^<>]*<\/ref>)*)([\r\n])/gi, '$1\n{' + '{fb cl3 qr|competition=$2}' + '}$3');
s = s.replace(/(\{\{[Ff]b[_ ]+ha[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*\}\})[\t \r\n]*\|\|*[^\|]*[\t ]*rowspan[\t ]*=[" ]*([0-9]+)[" ]*[^\|]*\|([^\r\n]*)/gi, '$1\n{' + '{fb ha qr|rows=$2|competition=$3}' + '}');
s = s.replace(/(\{\{[Ff]b[_ ]+ha[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*\}\})[\t \r\n]*\|\|*([^\}\-](?:[^\r\n=]|<ref[^<>\/]*\/>|<ref[^<>]*>(?:<[\/]*br[^<>]*>|[^<>])*<\/ref>)*)([\r\n])/gi, '$1\n{' + '{fb ha qr|competition=$2}' + '}$3');
k = k + 1;
}
s = s.replace(/<!--[\t ]*FB STYLE[\t ]*-->/g, '');
s = s.replace(/(<!--[\t ]*FB STYLE[^<>]*)width[ ]*:[ ]*[0-9]+px[; ]*/g, '$1');
s = s.replace(/<!--[\t ]*FB STYLE[\t ]*bgcolor[\t ]*=[" ]*([^"; ]*)[;" ]*\|[\t ]*-->/g, '<!-- FB COLOR: $1 -->');
s = s.replace(/<!--[\t ]*FB STYLE[\t ]*style[\t ]*=[" ]*background(?:\-color|)[\t ]*:[\t ]*([^"; ]*)[;" ]*\|[\t ]*-->/g, '<!-- FB COLOR: $1 -->');
var i = 0;
while(s.search(/<!-- FB COLOR: ([^<>]*) -->/g) >= 0 && s.search(/<!-- FB RBR FOOTER -->/g) >= 0 && i < 50) {
m = s.match(/<!-- FB COLOR: ([^<>]*) -->[\t ]*([HAWDL0-9PBC]*)/);
s = s.replace(/(<!-- FB RBR FOOTER -->)/g, '| color_' + m[2].toString() + ' = ' + m[1].toString() + '| text_' + m[2].toString() + ' =\n$1');
var r1 = new RegExp('<!-- FB COLOR:[\\t ]*' + m[1].toString() + '[\\t ]*-->([\\t ]*' + m[2].toString() + '[\\t ]*(?:\/|[\\r\\n]))', 'g');
s = s.replace(r1, '$1');
i = i + 1;
}
s = s.replace(/(\|[\s]*color_[0-9]+[\s]*=[\s]*)((?:[A-F0-9][A-F0-9][A-F0-9][A-F0-9][A-F0-9][A-F0-9]|[A-F0-9][A-F0-9][A-F0-9])[\s]*\|)/gi, '$1#$2');
s = s.replace(/\|[ ]*color_W[ ]*=[ ]*#?[A-Fa-f]+[ ]*\|[ ]*text_W[ ]*=[ ]*[\r\n]/g, '| color_W = green2 | text_W = Win\n');
s = s.replace(/\|[ ]*color_D[ ]*=[ ]*#?[A-Fa-f]+[ ]*\|[ ]*text_D[ ]*=[ ]*[\r\n]/g, '| color_D = yellow2 | text_D = Draw\n');
s = s.replace(/\|[ ]*color_T[ ]*=[ ]*#?[A-Fa-f]+[ ]*\|[ ]*text_T[ ]*=[ ]*[\r\n]/g, '| color_T = yellow2 | text_T = Tie\n');
s = s.replace(/\|[ ]*color_L[ ]*=[ ]*#?[A-Fa-f]+[ ]*\|[ ]*text_L[ ]*=[ ]*[\r\n]/g, '| color_L = red2 | text_L = Loss\n');
s = s.replace(/(<!-- FB RBR FOOTER -->[\t ]*[\r\n]*\}\})(?:<small>|[\t ]|[\r\n])*Source:([^\r\n]*)<\/small>[\t ]*([\r\n])/g, '|source=$2$3$1\n');
s = s.replace(/(<!-- FB RBR FOOTER -->[\t ]*[\r\n]*\}\})(?:<small>|[\t ]|[\r\n])*Source:([^\r\n]*)[\t ]*([\r\n])/g, '|source=$2$3$1\n');
s = s.replace(/<!-- FB RBR FOOTER -->[\t ]*[\r\n]*(\}\})/g, '\n$1');
if(s.search(/FB CL2 TEAM/g) >= 0) {
s = s.replace(/FB CL2 TEAM/g, 'fb cl2 team');
// FIX THIS
// if(s.search(/[Ff]b cl2? header[^{}]*winpoints/g) < 0) {
// if( 'y' == myPrompt('2pts?', 'y', true) ) {
// s = s.replace(/(fb cl2? header[^{}]*)/g, '$1|winpoints=2');
// }
// }
}
if(s.search(/FB HA TEAM/g) >= 0) {
s = s.replace(/FB HA TEAM/g, 'fb cl2 team|ha=y');
if(s.search(/[Ff]b ha header[^{}]*winpoints/g) < 0) {
if( 'y' == myPrompt('2pts?', 'y', true) ) {
s = s.replace(/(fb ha header[^{}]*)/g, '$1|winpoints=2');
}
}
}
s = s.replace(/(\{\{)fb ha header/g, '$1fb cl header|ha=y');
s = s.replace(/([\r\n])\|\-[\t ]*[\r\n]\|[\t ]*colspan[\t ]*=[\t "]*(?:8|9|10|11|12|13)[\t "]*style[\t ]*=[\t "]*background(?:\-color|)[\t ]*:[\t ]*#CCC[C]*[;"\t ]*\|[\t ]*([\r\n])/g, '$1{' + '{fb cl break}}$2');
s = s.replace(/([\r\n])\|\-[^\r\n]*AAA[^\r\n]*[\r\n]\|[\t \|]*([\r\n])/g, '$1{' + '{fb cl break}}$2');
s = s.replace(/([\r\n])\|[\t ]*rowspan[ ]*=[ "]*([0-9]+)[ "]*\|[ ]*([^\r\n]*)([\r\n]\{\{[Ff]b[_ ]*(?:cl2[_ ]*team|cl[0-9]*[_ ]*footer|cl[0-9]*[_ ]*hth))/g, '$1{{fb cl3 qr|rows=$2|competition=$3}}$4');
s = s.replace(/([\r\n])\|([^\-\}\r\n][^\r\n]*|)([\r\n]\{\{[Ff]b[_ ]*(?:cl2[_ ]*team|cl[0-9]*[_ ]*footer|cl[0-9]*[_ ]*hth))/g, '$1{{fb cl3 qr|competition=$2}}$3');
s = s.replace(/(competition[ ]*=[ ]*[^\{\}\[\]\|]*)rowspan[\t ]*=[\t "]*([0-9]+)[\t "]*/g, 'rows=$2|$1');
s = s.replace(/(competition[ ]*=[ ]*)(?:style[ ]*=[" ]*[^"\|\{\}=]*"|)[\t ]*\|/g, '$1');
s = s.replace(/(competition[ ]*=[ ]*)<small>((?:[^\{\}]|\{\{[^{}]*\}\})*)<\/small>(\}\})/g, '$1$2$3');
s = s.replace(/(bc[ ]*=)[ ]*((?:[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]|[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9])[ ]*(?:\||\}\}))/g, '$1#$2');
s = s.replace(/(\{\{[Ff]b[_ ]+(?:\{\{[^{}]*\}\}|[^{}])*\}\})[\t ]*[\r\n]*[\t ]*[\r\n]\|\}/g, '$1\n{' + '{end}' + '}');
s = s.replace(/(\{\{[Ff]b[_ ]+cl2?[_ ]+team[0-9a-z_ ]*(?:\|[ ]*p[ ]*=[^\|\[\]\{\}]*|)\|[ ]*t[ ]*=(?:[\[\]\{\}\|]|\[\[[^\[\]]*\]\]|\{\{[^{}]*\}\})*)[' ]*\(C\)[' ]*(\|)/g, '$1|champion=y$2');
s = s.replace(/(\{\{[Ff]b[_ ]+cl2?[_ ]+team[0-9a-z_ ]*(?:\|[ ]*p[ ]*=[^\|\[\]\{\}]*|)\|[ ]*t[ ]*=(?:[\[\]\{\}\|]|\[\[[^\[\]]*\]\]|\{\{[^{}]*\}\})*)[' ]*\(D\)[' ]*(\|)/g, '$1|disqualified=y$2');
s = s.replace(/(\{\{[Ff]b[_ ]+cl2?[_ ]+team[0-9a-z_ ]*(?:\|[ ]*p[ ]*=[^\|\[\]\{\}]*|)\|[ ]*t[ ]*=(?:[\[\]\{\}\|]|\[\[[^\[\]]*\]\]|\{\{[^{}]*\}\})*)[' ]*\(P\)[' ]*(\|)/g, '$1|promoted=y$2');
s = s.replace(/(\{\{[Ff]b[_ ]+cl2?[_ ]+team[0-9a-z_ ]*(?:\|[ ]*p[ ]*=[^\|\[\]\{\}]*|)\|[ ]*t[ ]*=(?:[\[\]\{\}\|]|\[\[[^\[\]]*\]\]|\{\{[^{}]*\}\})*)[' ]*\(C,[ ]*P\)[' ]*(\|)/g, '$1|champion=y|promoted=y$2');
s = s.replace(/(\{\{[Ff]b[_ ]+cl2?[_ ]+team[0-9a-z_ ]*(?:\|[ ]*p[ ]*=[^\|\[\]\{\}]*|)\|[ ]*t[ ]*=(?:[\[\]\{\}\|]|\[\[[^\[\]]*\]\]|\{\{[^{}]*\}\})*)[' ]*\(C\)[' ]\(*P\)[' ]*(\|)/g, '$1|champion=y|promoted=y$2');
s = s.replace(/(\{\{[Ff]b[_ ]+cl2?[_ ]+team[0-9a-z_ ]*(?:\|[ ]*p[ ]*=[^\|\[\]\{\}]*|)\|[ ]*t[ ]*=(?:[\[\]\{\}\|]|\[\[[^\[\]]*\]\]|\{\{[^{}]*\}\})*)[' ]*\(R\)[' ]*(\|)/g, '$1|relegated=y$2');
s = s.replace(/(\{\{[Ff]b[_ ]+cl2?[_ ]+team[0-9a-z_ ]*(?:\|[ ]*p[ ]*=[^\|\[\]\{\}]*|)\|[ ]*t[ ]*=(?:[\[\]\{\}\|]|\[\[[^\[\]]*\]\]|\{\{[^{}]*\}\})*)[' ]*\(O\)[' ]*(\|)/g, '$1|playoffwinner=y$2');
for(var i=1; i<=20; i++) {
var j = '(?:' + (i+1);
for(var i2=(i+2); i2<=21; i2++) {
j = j + '|' + i2;
}
j = j + ')';
var k=0;
var r = new RegExp('(\\|[\\t \\r\\n]*(?:color_|text_)'
+ j + '[\\t \\r\\n]*=(?:[^\\[\\]\\|\\{\\}]|\\[\\[[^\\[\\]]*\\]\\]|\\{\\{[^\\{\\}]*\\}\\}|\\[[^\\[\\]]*\]|[\\r\\n])*)(\\|[\\t \\r\\n]*(?:color_|text_)'
+ i + '[\\t \\r\\n]*=(?:[^\\[\\]\\|\\{\\}]|\\[\\[[^\\[\\]]*\\]\\]|\\{\\{[^\\{\\}]*\\}\\}|\\[[^\\[\\]]*\]|[\\r\\n])*)', 'gi');
while( s.search(r) >= 0 && k < 100) {
s = s.replace(r, '$2$1');
k = k + 1;
}
}
for(var i=1; i<=20; i++) {
var r1 = new RegExp('(\\|[\\s]*color_'+i+')([\\s]*=[\\s]*)([^\\[\\]\\{\\}\\|\\s]*)([\\s]*\\|[\\s]*text_'
+i+')([\\s]*=[\\s]*[\\r\\n])\\|[\\s]*color_'+(i+1)+'[\\s]*=[\\s]*\\3[\\s]*\\|[\\s]*text_'
+(i+1)+'[\\s]*=[\\s]*[\\r\\n]');
s = s.replace(r1, '$1-'+(i+1)+'$2$3$4-'+(i+1)+'$5');
r1 = new RegExp('(\\|[\\s]*color_[0-9]+)\\-'+i+'([\\s]*=[\\s]*)([^\\[\\]\\{\\}\\|\\s]*)([\\s]*\\|[\\s]*text_[0-9]+)\\-'
+i+'([\\s]*=[\\s]*[\\r\\n])\\|[\\s]*color_'+(i+1)+'[\\s]*=[\\s]*\\3[\\s]*\\|[\\s]*text_'
+(i+1)+'[\\s]*=[\\s]*[\\r\\n]');
s = s.replace(r1, '$1-'+(i+1)+'$2$3$4-'+(i+1)+'$5');
r1 = new RegExp('(\\|[\\s]*color_[0-9]+)\\-'+i+'([\\s]*=[\\s]*)([^\\[\\]\\{\\}\\|\\s]*)([\\s]*\\|[\\s]*text_[0-9]+)\\-'
+i+'([\\s]*=[\\s]*[\\r\\n])\\|[\\s]*color_'+(i+1)+'\-([0-9]+)[\\s]*=[\\s]*\\3[\\s]*\\|[\\s]*text_'
+(i+1)+'\\-\\6[\\s]*=[\\s]*[\\r\\n]');
s = s.replace(r1, '$1-$6$2$3$4-$6$5');
}
s = s.replace(/\{\|[\t ]*class="wikitable"[\t ]*style="text-align:[\t ]*center[;\t ]*"[\t ]*[\r\n](?:\|\-[\t ]*[\r\n]|)![\t ]*width[\t ]*=[\t ]*[0-9]+[\t ]*\|[\t ]* [\t ]*[\r\n]![\t ]*width[\t ]*=[\t ]*[0-9]+[\t ]*\|((?:[^\|\r\n]|\[\[[^\[\]]*\]\])*[\r\n])/g, '{'+'{fb r2 header|nt=1|$1');
var lt = '';
var j = 1;
while (lt != s) {
lt = s;
var re2 = new RegExp('(\\{\\{fb r2 header\\|nt)=' + j + '(\\|[^\\r\\n\\{\\}]*)[\\r\\n]![\t ]*width[\t ]*=[\t ]*[0-9]+[\t ]*(\\|(?:[^\\|\\r\\n]|\\[\\[[^\\[\\]]*\\]\\])*[\\r\\n])', 'g');
j = j + 1;
s = s.replace(re2, '$1=' + j + '$2$3');
s = s.replace(/(\{\{fb r2 header[^{}\r\n]*)([\r\n]\|\-)/g, '$1}'+'}$2');
s = s.replace(/(\{\{fb r(?:2 header|)\|[^{}\r\n]*\}\})[\t ]*[\r\n](?:\|\-[^\r\n]*[\r\n]|)![^\[\]\r\n\|]*\|((?:[^\r\n\|]|\[\[[^\[\]]*\]\])*)([\r\n])/g, '$1$3{'+'{fb r2 team|t=$2}'+'}$3');
s = s.replace(/(\{\{fb r(?:2 team|)\|[^{}\r\n]*\}\})[\t ]*[\r\n][\|!][——][\t ]*[\r\n]/g, '$1\n{'+'{fb r|r=null}'+'}\n');
s = s.replace(/(\{\{fb r(?:2 team|)\|[^{}\r\n]*\}\})[\t ]*[\r\n]\|(\[\[[^\[\]\|]*\|[0-9]+–[0-9]+\]\]|[0-9]+–[0-9]+)[\t ]*[\r\n]/g, '$1\n{'+'{fb r|s=$2}'+'}\n');
}
s = s.replace(/(\|[ ]*w[ ]*=[^{}]*)(<!--[ ]*FB PTS[^<>]*-->)/g, '$2$1');
s = s.replace(/<!--[ ]*FB PTS[– ]*-->/g, '');
s = s.replace(/(\|[ ]*pld[ ]*=[0-9 ]*\|[ ]*gf[ ]*=[0-9– ]*\|[ ]*ga[ ]*=[0-9– ]*)<!-- FB PTS ([0-9]+)[ ]*-->/g, '$1|bp=$2');
if (s.search(/loss_before_draw[ ]*=[ ]*true/) >= 0) {
s = s.replace(/(\|w[ ]*=[ ]*[0-9]+[ ]*)(\|d[ ]*=[ ]*)([0-9]+[ ]*)(\|l[ ]*=[ ]*)([0-9]+[ ]*)/g, '$1$4$3$2$5');
}
while(s.search(/<!--[ ]*FB PTS [0-9]+[ ]*-->\|[ ]*w[ ]*=[ ]*([0-9]+)[ ]*\|[ ]*ow[ ]*=[ ]*([0-9]+)[ ]*\|[ ]*ol[ ]*=[ ]*([0-9]+)/) >= 0) {
var wpts = 3;
var owpts = 2;
var olpts = 1;
var a = s.match(/<!--[ ]*FB PTS ([0-9]+)[ ]*-->\|[ ]*w[ ]*=[ ]*([0-9]+)[ ]*\|[ ]*ow[ ]*=[ ]*([0-9]+)[ ]*\|[ ]*ol[ ]*=[ ]*([0-9]+)/);
var bpts = Number(a[1]) - wpts*Number(a[2]) - owpts*Number(a[3]) - olpts*Number(a[4]);
var re = new RegExp('<!--[ ]*FB PTS ' + a[1] + '[ ]*-->(\\|[ ]*w[ ]*=[ ]*' + a[2] + '[ ]*\\|[ ]*ow[ ]*=[ ]*' + a[3] + '[ ]*\\|[ ]*ol[ ]*=[ ]*' + a[4] + '[^{}]*)', 'g');
s = s.replace(re, '$1|bp=' + bpts);
}
while(s.search(/<!--[ ]*FB PTS [0-9]+[ ]*-->\|[ ]*w[ ]*=[ ]*([0-9]+)[ ]*(?:\|[ ]*l[ ]*=[ ]*[0-9]+[ ]*|)\|[ ]*d[ ]*=[ ]*([0-9]+)/) >= 0) {
var wpts = 3;
var dpts = 1;
if (s.search(/winpoints[ ]*=[ ]*2/g) >=0 || s.search(/wpts[ ]*=[ ]*2/g) >=0 ) {
wpts = 2;
}
if (s.search(/winpoints[ ]*=[ ]*4/g) >=0 || s.search(/wpts[ ]*=[ ]*4/g) >=0 ) {
wpts = 4;
}
if (s.search(/drawpoints[ ]*=[ ]*2/g) >=0 || s.search(/dpts[ ]*=[ ]*2/g) >=0 ) {
dpts = 2;
}
var a = s.match(/<!--[ ]*FB PTS ([0-9]+)[ ]*-->\|[ ]*w[ ]*=[ ]*([0-9]+)[ ]*(?:\|[ ]*l[ ]*=[ ]*[0-9]+[ ]*|)\|[ ]*d[ ]*=[ ]*([0-9]+)/);
var bpts = Number(a[1]) - wpts*Number(a[2]) - dpts*Number(a[3]);
var re = new RegExp('<!--[ ]*FB PTS ' + a[1] + '[ ]*-->(\\|[ ]*w[ ]*=[ ]*' + a[2] + '[ ]*(?:\\|[ ]*l[ ]*=[ ]*[0-9]+[ ]*|)\\|[ ]*d[ ]*=[ ]*' + a[3] + '[^{}]*)', 'g');
s = s.replace(re, '$1|bp=' + bpts);
}
s = s.replace(/\|[ ]*(?:bp|adjust_points_[^=]*)=[ ]*0[ ]*([^0-9])/g, '$1');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2?[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*)[ ']*\(C\)[' ]*\(P\)[' ]*(\|[ ]*w[ ]*=)/g, '$1|champion=y|promoted=y$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2?[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*)[ ']*\(C,[ ]*P\)[' ]*(\|[ ]*w[ ]*=)/g, '$1|champion=y|promoted=y$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2?[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*)[ ']*\(C\)[' ]*\(Q\)[' ]*(\|[ ]*w[ ]*=)/g, '$1|champion=y|qualified=y$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2?[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*)[ ']*\(C,[ ]*Q\)[' ]*(\|[ ]*w[ ]*=)/g, '$1|champion=y|qualified=y$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2?[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*)[ ']*\(R\)[' ]*(\|[ ]*w[ ]*=)/g, '$1|relegated=y$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2?[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*)[ ']*\(Q\)[' ]*(\|[ ]*w[ ]*=)/g, '$1|qualified=y$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2?[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*)[ ']*\(O\)[' ]*(\|[ ]*w[ ]*=)/g, '$1|playoffwinner=y$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2?[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*)[ ']*\(C\)[' ]*(\|[ ]*w[ ]*=)/g, '$1|champion=y$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2?[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*)\|[ ]*bc[ ]*=[ ]*(?:white|#?f*)[ ]*(\||\}\})/gi, '$1$2');
if(s.search(/winpoints=2/g) < 0) {
if(s.search(/\{\{[_ ]*[Ff]b[_ ]+cl2?[_ ]+team(?:\{\{[^{}]*\}\}|[^{}₳])*\|w[ ]*=[ ]*([0-9]+)(?:\{\{[^{}]*\}\}|[^{}₳])*\|[ ]*bp[ ]*=[ ]*\-\1[\t ]*(?:\||\}\})/g) >= 0) {
alert('Attempting to adjust to 2 points!');
s = s.replace(/(\|[ ]*bp)([ ]*=)/g, '$1₳$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2?[_ ]+team(?:\{\{[^{}]*\}\}|[^{}₳])*\|w[ ]*=[ ]*0(?:\{\{[^{}]*\}\}|[^{}₳])*)(\}\})/g, '$1|bp₳=-0$2');
if(s.search(/(\{\{[_ ]*[Ff]b[_ ]+cl2?[_ ]+team(?:\{\{[^{}]*\}\}|[^{}₳])*\}\})/g) < 0) {
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2?[_ ]+header[^{}]*)/g, '$1|winpoints=2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2?[_ ]+team(?:\{\{[^{}]*\}\}|[^{}₳])*\|w[ ]*=[ ]*)([0-9]+)((?:\{\{[^{}]*\}\}|[^{}₳])*)\|[ ]*bp₳[ ]*=[ ]*\-\2[\t ]*(\||\}\})/g, '$1$2$3$4');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2?[_ ]+team(?:\{\{[^{}]*\}\}|[^{}₳])*\|w[ ]*=[ ]*)([0-9]+)((?:\{\{[^{}]*\}\}|[^{}₳])*)\|[ ]*bp₳[ ]*=[ ]*(\-?[0-9]+)(\||\}\})/g, '$1$2$3|bp={'+'{subst:#expr:$4+$2}'+'}$5');
} else {
s = s.replace(/(\|[ ]*bp)₳([ ]*=)/g, '$1$2');
}
}
}
var a = s.match(/\{\{subst:#expr:[ ]*([0-9]+)[ ]*\+[ ]*([0-9]+)[ ]*\}\}/);
if (a) {
var ap = Number(a[1]) + Number(a[2]);
var rexp = new RegExp('\\{\\{subst:#expr:[ ]*' + a[1] + '[ ]*\\+[ ]*' + a[2] + '[ ]*\\}\\}');
s = s.replace(rexp, ap);
}
a = s.match(/\{\{subst:#expr:[ ]*\-([0-9]+)[ ]*\+[ ]*([0-9]+)[ ]*\}\}/);
if (a) {
var ap = -Number(a[1]) + Number(a[2]);
var rexp = new RegExp('\\{\\{subst:#expr:[ ]*\\-' + a[1] + '[ ]*\\+[ ]*' + a[2] + '[ ]*\\}\\}');
s = s.replace(rexp, ap);
}
return s;
}
// -------------------------------------------------------------------------------- //
function wpFbCols(s)
{
s = s.replace(/[\r\n]\{\|[\t ]*width[\t ]*=[\t ]*100%[\t ]*[\r\n]\|[\t ]*valign[\t ]*=[\t ]*top[\t ]*width[\t ]*=[\t ]*50%[\t ]*\|[\t ]*[\r\n]/g, '\n{'+'{col-begin}'+'}\n{'+'{col-2}'+'}\n');
s = s.replace(/[\r\n]\|[\t ]*style[\t ]*=[\t "]*vertical\-align[\t ]*:[\t ]*top[; ]*width[\t ]*:[\t ]*50%[; ]*[\t "]*[\t ]*\|[\t ]*[\r\n]/g, '\n{' + '{col-2}' + '}\n');
s = s.replace(/[\r\n]\|[\t ]*(?:valign[\t ]*=[\t "]*top[\t "]*|)[\t ]*width[\t ]*=[\t "]*50%[\t "](?:valign[\t ]*=[\t "]*top[\t "]*|)[\t ]*\|[\t ]*[\r\n]/g, '\n{' + '{col-2}' + '}\n');
s = s.replace(/[\r\n]\|[\t ]*(?:valign[\t ]*=[\t "]*top[\t "]*|)[\t ]*style[\t ]*=[\t "]*width[\t ]*:[\t "]*50%[;\t "](?:valign[\t ]*=[\t "]*top[\t "]*|)[\t ]*\|[\t ]*[\r\n]/g, '\n{' + '{col-2}' + '}\n');
s = s.replace(/[\r\n]\|[\t ]*(?:valign[\t ]*=[\t "]*top[\t "]*|)[\t ]*width[\t ]*=[\t "]*33[\.3]*%[\t "](?:valign[\t ]*=[\t "]*top[\t "]*|)[\t ]*\|[\t ]*[\r\n]/g, '\n{' + '{col-3}' + '}\n');
s = s.replace(/[\r\n]\|[\t ]*(?:valign[\t ]*=[\t "]*top[\t "]*|)[\t ]*style[\t ]*=[\t "]*width[\t ]*:[\t "]*33[\.3]*%[;\t "](?:valign[\t ]*=[\t "]*top[\t "]*|)[\t ]*\|[\t ]*[\r\n]/g, '\n{' + '{col-3}' + '}\n');
s = s.replace(/[\r\n]\|[\t ]*(?:valign[\t ]*=[\t "]*top[\t "]*|)[\t ]*width[\t ]*=[\t "]*25%[\t "](?:valign[\t ]*=[\t "]*top[\t "]*|)[\t ]*\|[\t ]*[\r\n]/g, '\n{' + '{col-4}' + '}\n');
s = s.replace(/[\r\n]\|[\t ]*(?:valign[\t ]*=[\t "]*top[\t "]*|)[\t ]*style[\t ]*=[\t "]*width[\t ]*:[\t "]*25%[;\t "](?:valign[\t ]*=[\t "]*top[\t "]*|)[\t ]*\|[\t ]*[\r\n]/g, '\n{' + '{col-4}' + '}\n');
s = s.replace(/[\r\n]\|[\t ]*style[\t ]*=[\t "]*vertical\-align[\t ]*:[\t ]*top[; ]*[\t "]*\|[\t "]*[\r\n]*(\{\{col\-)/g, '\n{' + '{col-break}' + '}\n$1');
s = s.replace(/[\r\n]\{\|(?:table|[\t ])*style[\t ]*=[\t "]*width[\t ]*:[\t "]*100%[;\t "]*[\r\n](?:\|\-[\t ]*[\r\n]|)([\r\n]\{\{col\-)/gi, '\n{' + '{col-begin}' + '}$1');
s = s.replace(/[\r\n]\{\|(?:table|[\t ])*width[\t ]*=[\t "]*100%[\t "]*[\r\n](?:\|\-[\t ]*(?:valign[\t ]*=[\t "]*top[\t "]*|)[\t ]*[\r\n]|)(\{\{col\-)/g, '\n{' + '{col-begin}' + '}\n$1');
s = s.replace(/[\r\n]\{\|(?:table|[\t ])*style[\t ]*=[\t "]*width[\t ]*:[\t "]*100%[;\t "]*[\r\n](?:\|\-[\t ]*(?:valign[\t ]*=[\t "]*top[\t "]*|)[\t ]*[\r\n]|)(\{\{col\-)/g, '\n{' + '{col-begin}' + '}\n$1');
s = s.replace(/[\t ]*([\r\n]\|\})[\t ]*([\r\n])\|\}([^\}])/g, '$1$2{' + '{col-end}' + '}$3');
s = s.replace(/([\r\n])\|(?:[\t ]*valign[ ]*=[" ]*top[" ]*[\t ]*\||)[\t ]*((?:<(?:\{\{subst:void\}\}|)!--[^<>\r\n]*-->|[\t ]*)[\r\n]\{\{col\-[0-9])/gi, '$1{' + '{col-break}' + '}$2');
s = s.replace(/([\r\n])\|(?:[\t ]*valign[ ]*=[" ]*top[" ]*[\t ]*\||)[\t ]*([\r\n]\{\|)/gi, '$1{' + '{col-break}' + '}$2');
s = s.replace(/([\r\n])\{\| border=0 cellpadding=0 cellspacing=0[\t ]*([\r\n]\{\{col\-(?:[0-9]|break))/g, '$1{' + '{col-begin|width=auto}' + '}$2');
s = s.replace(/([\r\n])[\t ]*\{\|[\t ]*[^\r\n]*[\r\n](?:\|\-[^\r\n]*[\r\n]|)\|[\t ]*[\r\n]*(\{\{[Ff]ootball kit[^{}]*\}\})[\r\n\|\t ]*(\{\{[Ff]ootball kit[^{}]*\}\})[\t\r\n ]*[\r\n][\t ]*\|\}/g, '$1{'+'{col-begin}'+'}\n{'+'{col-2}'+'}\n$2\n{'+'{col-2}'+'}\n$3\n{'+'{col-end}'+'}');
s = s.replace(/[\t ]*<\/div>[\t ]*[\r\n]*[\t ]*<div[\t ]*style[\t ]*=[" ]*float[\t ]*:[\t ]*(?:left|right)[; ]*width[\t ]*:[\t ]*([0-9]+%)[; "]*>/gi, '{' + '{col-float-break|width=$1}' + '}');
s = s.replace(/[\t ]*([\r\n])[\t ]*<div[\t ]*style[\t ]*=[" ]*float[\t ]*:[\t ]*left[; ]*width[\t ]*:[\t ]*([0-9]+%)[; "]*>/gi, '$1{' + '{col-float|width=$2}' + '}');
s = s.replace(/[\t ]*[\r\n][\t ]*<div[\t ]*style[\t ]*=[" ]*float[\t ]*:[\t ]*center[^<>]*>[\t ]*[\r\n]/g, '<!-- DIV MARK -->');
for (var k=0; k<20; k++) {
s = s.replace(/(<!-- DIV MARK -->)([^<>\r\n]*[\r\n])/g, '$2$1');
s = s.replace(/<!-- DIV MARK -->[\t ]*<\/div>[\t ]*[\r\n]*[\t ]*\{\{(?:\-|Clear|Clr)\}\}[\t ]*[\r\n]*/, '');
}
s = s.replace(/[\t ]*<\/div>[\t ]*[\r\n]*[\t ]*\{\{(?:\-|Clear|Clr)\}\}/gi, '{' + '{col-float-end}' + '}');
return s;
}
// -------------------------------------------------------------------------------- //
function wpFbCl(s,f,ts)
{
var oldtext = s;
var lt = '';
while(lt != s) {
lt = s;
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2?[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*)[ ']*\(C\)[' ]*\(P\)[' ]*(\|[ ]*w[ ]*=)/g, '$1|champion=y|promoted=y$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2?[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*)[ ']*\(C,[ ]*P\)[' ]*(\|[ ]*w[ ]*=)/g, '$1|champion=y|promoted=y$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2?[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*)[ ']*\(R\)[' ]*(\|[ ]*w[ ]*=)/g, '$1|relegated=y$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2?[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*)[ ']*\(O\)[' ]*(\|[ ]*w[ ]*=)/g, '$1|playoffwinner=y$2');
s = s.replace(/(\{\{[_ ]*[Ff]b cl[^{}]*)\|[\s ]*(\||\}\})/g, '$1$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+(?:(?:ha|cl3)[_ ]+qr|cl2[_ ]+team)(?:\{\{[^{}]*\}\}|[^{}])*)[\s][\s]*(\||=|\}\}|\])/g, '$1$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+(?:(?:ha|cl3)[_ ]+qr|cl2[_ ]+team)(?:\{\{[^{}]*\}\}|[^{}])*[\|=\[])[\s][\s]*/g, '$1');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+(?:(?:ha|cl3)[_ ]+qr|cl2[_ ]+team)(?:\{\{[^{}]*\}\}|[^{}])*)\{\{nowrap\|([^{}]*)\}\}/gi, '$1$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+(?:(?:ha|cl3)[_ ]+qr|cl2[_ ]+team)(?:\{\{[^{}]*\}\}|[^{}])*) /gi, '$1 ');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+(?:(?:ha|cl3)[_ ]+qr|cl2[_ ]+team)(?:\{\{[^{}]*\}\}|[^{}])*)\{\{0\}\}/gi, '$1 ');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+(?:(?:ha|cl3)[_ ]+qr|cl2[_ ]+team)(?:\{\{[^{}]*\}\}|[^{}])*)<[\/ ]*br[\/ ]*>/gi, '$1 ');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+(?:(?:ha|cl3)[_ ]+qr|cl2[_ ]+team)(?:\{\{[^{}]*\}\}|[^{}])*[^'])''([^'])/gi, '$1$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+(?:(?:ha|cl3)[_ ]+qr|cl2[_ ]+team)(?:\{\{[^{}]*\}\}|[^{}])*[^'])'''([^'])/gi, '$1$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+(?:cl2[_ ]+team)(?:\{\{[^{}]*\}\}|[^{}])*)(\}\})\{\{[Rr]ef\|[^{}\|]*\|([^{}\|]*)\}\}/g, '$1|pn=$3$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+(?:(?:ha|cl3)[_ ]+qr)(?:\{\{[^{}]*\}\}|[^{}])*)(\}\})\{\{[Rr]ef\|[^{}\|]*\|([^{}\|]*)\}\}/g, '$1|nt=$3$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[^{}]*)\|[\t ]*[A-Za-z0-9_\t ]+=[\t ]*(\||\}\})/g, '$1$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*)(\}\})[\t ]*[\r\n][\t ]*\{\{[_ ]*[Ff]b[_ ]+(?:ha|cl3)[_ ]+qr[_ ]*\|[ ]*competition[ ]*=[ ]*\(([0-9]+)\)[ ]*\}\}/g, '$1|bp=$3$2');
s = s.replace(/[\t \|]+(\{\{[_ ]*[Ff]b[_ ]+(?:cl3[_ ]+qr|cl2[_ ]+team))/g, '\n$1');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+(?:ha|cl3)[_ ]+qr[^{}]*)\{\{[_ ]*[Rr]ef[_ ]*\|[^{}\|]*\|([^{}\|]*)\}\}[\t ]*(\}\})/g, '$1|nt=$2$3');
s = s.replace(/\{\{[_ ]*[Ff]b[_ ]+(?:ha|cl3)[_ ]+qr[_ ]*(?:\|[\s]*rows[\s]*=[\s0-9]*|)\|[\s]*competition[\s]*=[\s]*\}\}[\s]*/g, '');
s = s.replace(/(\{\{#invoke:[Ss]ports[_ ]+rbr[_ ]+table(?:\{\{{^{}]*\}\}|[^{}])*\|[ ]*(?:color|text)_)([0-9]+[ ]*=)/g, '$1<!-- MANGLE -->$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+(?:cl2?|ha)[_ ]+team[^\|]*)(\|[ ]*p[ ]*=[^\|\{\}\[\]]*)(\|[ ]*rows[ ]*=[ ]*[0-9]*)(\|)/g, '$1$3$2$4');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+(?:cl2?|ha)[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*)(\|[ ]*l[ ]*=[ ]*[0-9]+[ ]*)(\|[ ]*d[ ]*=[ ]*[0-9]*[ ]*)(\|)/g, '$1$3$2$4');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+(?:cl2?|ha)[_ ]+team[^\|]*)\|[ ]*rows[ ]*=[ ]*2[ ]*(\|[ ]*p[ ]*=[^\|\{\}\[\]]*)(\|[^\r\n]*[\r\n]\{\{[_ ]*[Ff]b[_ ]+(?:cl2?|ha)[_ ]+team[^\|]*)/g, '$1$2$3$2');
}
s = s.replace(/(\{\{)[_ ]*[Ff]b[_ ]+cl2[_ ]+header(?:[_ ]+navbar|)[_ ]*(\||\}\})/g, '$1fb cl header|show_positions=n$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2?[_ ]+header[^{}]*)\|[ ]*loss_before_ot[ ]*=[0-9 a-z]*(\||\}\})/g, '$1$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2?[_ ]+header[^{}]*)\|[ ]*OT[ ]*=[0-9 a-z]*(\||\}\})/gi, '$1$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2?[_ ]+header[^{}]*)<!--[\t ]*\|[\t ]*hth[\t ]*=[a-z ]*-->/g, '$1');
s = s.replace(/\{\{[_ ]*[Ff]b[_ ]+(?:ha|cl3)[_ ]+qr[_ ]*(?:\|[ ]*rows[ ]*=[0-9 ]*|\|[ ]*competition[ ]*=|[ ])*\}\}[\t ]*[\r\n]/g, '');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+(?:ha|cl3)[_ ]+qr[_ ]*(?:[^{}\[\]]|\[\[[^\[\]]*\]\]|\{\{[^{}]*\}\})*)[\s]*\|[\s]*bc[\s]*=[\sA-Z0-9\#]*(\||\}\})/g, '$1$2');
s = s.replace(/(\{\{)[_ ]*[Ff]b[_ ]+Allsvenskan[_ ]+play\-offs[_ ]+team[_ ]+footer/g, '$1fb cl footer|orfc=1) points; 2) goal difference; 3) number of goals scored.');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2?[_ ]+hth[^{}]*)<small>/g, '$1');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2?[_ ]+hth[^{}]*)<\/small>/g, '$1');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2?[_ ]+hth[^{}]*\|)[ ]*\|/g, '$1');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2?[_ ]+hth[^{}]*)\|[ ]*rows[ ]*=[0-9 ]*/g, '$1');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2?[_ ]+hth[^{}]*)\|[ ]*qr[ ]*=[a-z ]*/g, '$1');
for (var kb=0; kb<4; kb++) {
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2?[_ ]+hth[^{}]*)[\t ]*<[\/ ]*[Bb][Rr][^<>]*>[\t ]*/g, '$1; ');
}
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl[_ ]+header[^{}]*)\|[ ]*template[ ]*=[no ]*\|[ ]*name[ ]*=([^{}\|]*)/g, '<!--$2-->$1');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl[_ ]+header[^{}]*)\|[ ]*template[ ]*=[no ]*/g, '$1');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl[_ ]+header[^{}]*)\|[ ]*(?:hth|champion|qr-width|noqr)[ ]*=[0-9a-z ]*(\||\}\})/g, '$1$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl[_ ]+header[^{}]*)(\}\}[\t ]*[\r\n]*[\t ]*\{\{[_ ]*[Ff]b[_ ]+cl2?[_ ]+team)[_ ]+2pts/g, '$1|winpoints=2$2');
s = s.replace(/(\{\{)[_ ]*[Ff]b[_ ]+cl2?[_ ]+header[_ ]*\|[ ]*PKOT[ ]*=[ ]*y[ ]*(\||\}\})/g, '<!-- FB PK OT -->$1#invoke:sports table|main|style=WL OT\n|res_col_header=RESCOLHEADER\n<!-- FB POS 0-->$2');
s = s.replace(/(\{\{)[_ ]*[Ff]b[_ ]+cl2?[_ ]+header[_ ]*\|ha=y(\||\}\})/g, '$1#invoke:sports table|main|style=WDLHA\n|res_col_header=RESCOLHEADER\n<!-- FB POS 0-->$2');
s = s.replace(/(\{\{)[_ ]*[Ff]b[_ ]+cl2?[_ ]+header(?:[_ ]+navbar|)[_ ]*(\||\}\})/g, '$1#invoke:sports table|main|style=WDL\n|res_col_header=RESCOLHEADER\n<!-- FB POS 0-->$2');
if (s.search(/football league season/gi) >= 0) {
s = s.replace(/(RESCOLHEADER)/g, '$1\n|show_limit=5');
}
lt = '';
while(lt != s) {
lt = s;
s = s.replace(/(<!-- FB POS 0-->)[\t ]*\|[\t ]*template[ ]*=[\t ]*yes[\t ]*\|[ ]*name[\t ]*=[^{}\|]*(\||\}\})/g, '|template_name={' + '{subst:#invoke:string|replace|{' + '{subst:PAGENAME}' + '}|'|\'}' + '}\n|showteam = {' + '{' + '{showteam|}' + '}' + '}\n$1$2');
s = s.replace(/(<!-- FB POS 0-->)[\t ]*\|[\t ]*promoted[\t ]*=[\t ]*[a-z0-9][a-z0-9 ]*(\||\}\})/g, '|res_col_header=PR\n$1$2');
s = s.replace(/(<!-- FB POS 0-->)[\t ]*\|[\t ]*qualification[\t ]*=[\t ]*[a-z0-9 ]*(\||\}\})/g, '$1$2');
s = s.replace(/(<!-- FB POS 0-->)[\t ]*\|[\t ]*sort(?:able|)[\t ]*=[\t ]*[a-z0-9][a-z0-9 ]*(\||\}\})/g, '|sortable_table=y\n$1$2');
s = s.replace(/(<!-- FB POS 0-->)[\t ]*\|[\t ]*gavg[\t ]*=[\t ]*[a-z0-9][a-z0-9 ]*(\||\}\})/g, '|use_goal_ratio=y\n$1$2');
s = s.replace(/(<!-- FB POS 0-->)[\t ]*\|[\t ]*winpoints[\t ]*=[\t ]*([0-9]+)[ ]*(\||\}\})/g, '|winpoints=$2\n$1$3');
s = s.replace(/(<!-- FB POS 0-->)[\t ]*\|[\t ]*drawpoints[\t ]*=[\t ]*([0-9]+)[ ]*(\||\}\})/g, '|drawpoints=$2\n$1$3');
s = s.replace(/(<!-- FB POS 0-->)[\t ]*\|[\t ]*losspoints[\t ]*=[\t ]*([0-9]+)[ ]*(\||\}\})/g, '|losspoints=$2\n$1$3');
s = s.replace(/(<!-- FB POS 0-->)[\t ]*\|[\t ]*show_positions[\t ]*=[\t ]*([a-z]+)[ ]*(\||\}\})/g, '|show_positions=$2\n$1$3');
s = s.replace(/(<!-- FB POS 0-->)[\t ]*\|[\t ]*showpk[\t ]*=[\t ]*y[\t ]*(\||\}\})/g, '|showpk='+'y\n$1$2');
s = s.replace(/(<!-- FB POS 0-->)[\t ]*\|[\t ]*(?:teamwidth|t\-width)[\t ]*=[\t ]*([0-9]+|auto)[ ]*(\||\}\})/g, '|teamwidth=$2\n$1$3');
s = s.replace(/(<!-- FB POS 0-->)[\t ]*\|[\t ]*ptsfirst[\t ]*=[\t ]*[a-z0-9][a-z0-9 ]*(\||\}\})/g, '|ptsfirst=y\n$1$2');
s = s.replace(/(<!-- FB POS 0-->)[\t ]*\|[\t ]*title[\t ]*=[\t ]*((?:[^\|\{\}\[\]]|\[\[[^\[\]]*\]\]|\{\{[^{}]*\}\})*)[ ]*(\||\}\})/g, '|title=$2\n$1$3');
s = s.replace(/(<!-- FB POS 0-->)[\t ]*(\|[\t ]*loss_before_draw[\t ]*=[\t ]*[a-z]+)/g, '$2$1');
s = s.replace(/(<!-- FB POS 0-->)[\t ]*(\|[\t ]*ranking_style[\t ]*=[\t ]*[a-z]+)/g, '$2$1');
s = s.replace(/(<!-- FB POS 0-->)[\t ]*(\|[\t ]*for_against_style[\t ]*=[\t ]*[a-z]+)/g, '$2$1');
s = s.replace(/(<!-- FB POS 0-->)[\t ]*(\|[\t ]*show_tries[\t ]*=[\t ]*[a-z]+)/g, '$2$1');
s = s.replace(/(<!-- FB POS 0-->)[\t ]*(\|[\t ]*use_tie[\t ]*=[\t ]*[a-z]+)/g, '$2$1');
s = s.replace(/(<!-- FB POS 0-->)[\t ]*(\|[\t ]*loss_before_(?:draw|tie)[\t ]*=[\t ]*[a-z]+)/g, '$2$1');
s = s.replace(/(<!-- FB POS 0-->)[\t ]*(\|[\t ]*nodraw[\t ]*=[\t ]*[a-z]+)/g, '$2$1');
s = s.replace(/(<!-- FB POS 0-->)[\t ]*(\|[\t ]*res_col_header[\t ]*=[\t ]*[^{}\|]*)/g, '$2$1');
s = s.replace(/(<!-- FB POS 0-->)[\t ]*(\|[\t ]*use_(?:goal|point)_percentage[\t ]*=[\t ]*[a-z]+)/g, '$2$1');
s = s.replace(/(<!-- FB POS 0-->)[\t ]*\|[\t ]*nopos[\t ]*=[\t ]*[a-z]+/g, '|show_positions=n\n$1');
s = s.replace(/(<!-- FB POS 0-->)[\t ]*\|[\t ]*group[\t ]*=[\t ]*[a-z]+/g, '|show_groups=y\n|group_header=\n$1');
s = s.replace(/(<!-- FB POS 0-->)[\t ]*(\|[\t ]*status_text_P[\t ]*=[\t ]*[A-Za-z]+)/g, '$2$1');
}
s = s.replace(/<!-- FB POS 0-->[\t ]*[\r\n]*[\t ]*\}\}[\t ]*[\r\n]*/g, '\n<!-- FB POS 1-->');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl[^{}]*\|)[ ]*\|/g, '$1');
s = s.replace(/\|[ ]*bc[ ]*=[# ]*(\||\}\})/g, '$1');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team)[_ ]+2pts/g, '$1');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*\|)[ ]*nat[ ]*=[ ]*\|/g, '$1');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*\|[\t ]*t[\t ]*=[\t ]*)([A-Z][A-Za-z0-9 ]*[A-Za-z0-9])([ ]*\|)/g, '$1[[$2]]<!-- UNLINK -->$3');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*)\|[ ]*border[ ]*=[ ]*(\||\}\})/g, '$1$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*)\|[ ]*border[ ]*=[ ]*[a-z]+[ ]*(\}\})/g, '$1$2\n{'+'{fb cl break}'+'}');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*)\|[ ]*bc[ ]*=[# ]*(\||\}\})/g, '$1$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*)(\|[ ]*[bd]p[ ]*=[ ]*[0-9\.]+[ ]*)([^{}]*)/g, '$1$3$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*)(\|[ ]*pn[ ]*=[ ]*[^\|\{\}]+[ ]*)([^{}]*)/g, '$1$3$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*)\|[ ]*gavg[ ]*=[a-z ]*(\||\}\})/g, '$1$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*)(\}\})[\t ]*<sup>([^<>]*)<\/sup>/gi, '$1|pn=$3$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*)(\}\})[\t ]*\(([\+\-][0-9]+)\)/gi, '$1|pn=$3$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*)(\}\})[\t ]*([\*†‡]+)/gi, '$1|pn=$3$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+(?:ha|cl3)[_ ]+qr[^{}]*)(\}\})[\t ]*<sup>([^<>]*)<\/sup>/gi, '$1$3$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*)(\}\})[\t ]*(\{\{ref[^{}]*\}\})/gi, '$1|pn=$3$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+(?:ha|cl3)[_ ]+qr[^{}]*)(\}\})[\t ]*(\{\{ref[^{}]*\}\})/gi, '$1$3$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+(?:ha|cl3)[_ ]+qr[^{}]*)\|[ ]*(?:promoted|promotion|qualified|qualification|relegated|relegation)[ ]*=[ ]*(\||\}\})/g, '$1$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+(?:ha|cl3)[_ ]+qr[^{}]*)\|[ ]*qr[ ]*=[ ]*[a-z]*[ ]*(\||\}\})/g, '$1$2');
s = s.replace(/\{\{[_ ]*[Ff]b[_ ]+(?:ha|cl3)[_ ]+qr[_ ]*(?:\|[ ]*rows[ ]*=[0-9 ]*|)[\| ]*\}\}[\t ]*[\r\n]/g, '');
for (var kb=0; kb<3; kb++) {
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*)\|[ ]*(?:champion|promoted|playoffwinner|qualified|tournamentqualified|advances|relegationqualified|disqualified|eliminated|relegated|allsvenskanchampion|swedishchampion)[ ]*=[ ]*(\||\}\})/g, '$1$2');
}
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*)\|[ ]*champion[ ]*=[ ]*[A-Za-z0-9][^\|{}]*(\||\}\})/g, '$1|status=C$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*)\|[ ]*promoted[ ]*=[ ]*[A-Za-z0-9][^\|{}]*(\||\}\})/g, '$1|status=P$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*)\|[ ]*qualified[ ]*=[ ]*[A-Za-z0-9][^\|{}]*(\||\}\})/g, '$1|status=Q$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*)\|[ ]*playoffwinner[ ]*=[ ]*[A-Za-z0-9][^\|{}]*(\||\}\})/g, '$1|status=O$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*)\|[ ]*tournamentqualified[ ]*=[ ]*[A-Za-z0-9][^\|{}]*(\||\}\})/g, '$1|status=T$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*)\|[ ]*advances[ ]*=[ ]*[A-Za-z0-9][^\|{}]*(\||\}\})/g, '$1|status=A$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*)\|[ ]*relegationqualified[ ]*=[ ]*[A-Za-z0-9][^\|{}]*(\||\}\})/g, '$1|status=RQ$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*)\|[ ]*disqualified[ ]*=[ ]*[A-Za-z0-9][^\|{}]*(\||\}\})/g, '$1|status=D$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*)\|[ ]*eliminated[ ]*=[ ]*[A-Za-z0-9][^\|{}]*(\||\}\})/g, '$1|status=E$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*)\|[ ]*relegated[ ]*=[ ]*[A-Za-z0-9][^\|{}]*(\||\}\})/g, '$1|status=R$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*)\|[ ]*allsvenskanchampion[ ]*=[ ]*[A-Za-z0-9][^\|{}]*(\||\}\})/g, '$1|status_text_C=Allsvenskan Champion|status=C$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*)\|[ ]*swedishchampion[ ]*=[ ]*[A-Za-z0-9][^\|{}]*(\||\}\})/g, '$1|status_text_S=Swedish Champion|status=S$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+(?:ha|cl3)[_ ]+qr[^{}]*)\|[ ]*rows[ ]*=[ ]*1?[ ]*(\||\}\})/g, '$1$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+(?:ha|cl3)[_ ]+qr[^{}]*)\|[ ]*qualification[ ]*=[ ]*(\||\}\})/g, '$1$2');
for(var k1=0; k1<5; k1++) {
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*)\|status=([A-Z,]+)((?:\|[^{}]*|))(\|status=)([A-Z,]+)/g, '$1$3$4$2,$5');
s = s.replace(/(\|[ ]*status[ ]*=[ ]*)([E]),?([RCOPQD])/g, '$1$3,$2');
s = s.replace(/(\|[ ]*status[ ]*=[ ]*)([DE]),?([RCOPQ])/g, '$1$3,$2');
s = s.replace(/(\|[ ]*status[ ]*=[ ]*)([QDE]),?([RCOP])/g, '$1$3,$2');
s = s.replace(/(\|[ ]*status[ ]*=[ ]*)([PQDE]),?([RCO])/g, '$1$3,$2');
s = s.replace(/(\|[ ]*status[ ]*=[ ]*)([OPQDE]),?([RC])/g, '$1$3,$2');
s = s.replace(/(\|[ ]*status[ ]*=[ ]*)([COPQDE]),?([R])/g, '$1$3,$2');
}
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*)(\|[ ]*status[ ]*=[^\|\{\}]*)(\|[^{}]*)(\}\})/g, '$1$3$2$4');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*)(\|[ ]*bc[ ]*=[^\|\{\}]*)(\|[^{}]*)(\}\})/g, '$1$3$2$4');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*)(\|[ ]*pn[ ]*=[^\|\{\}]*)(\|[ ]*[bd]p[ ]*=[\-0-9 ]*)(\||\}\})/g, '$1$3$2$4');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+(?:ha|cl3)[_ ]+qr)[_ ]*(\|(?:\{\{[^{}]*\}\}|[^{}])*)(\|[ ]*(?:promoted|promotion|qualified|qualification|relegated|relegation)[ ]*=[A-Za-z0-9 ]*)(\||\}\})/g, '$1$3$2$4');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+(?:ha|cl3)[_ ]+qr[^{}]*)\|[ ]*(?:promoted|promotion)[ ]*=[ ]*[a-z0-9][a-z0-9]*[ ]*((?:\|[ ]*rows[ ]*=[ 0-9]*|)\|[ ]*competition[ ]*=)[ ]*/g, '$1$2 Promotion to ');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+(?:ha|cl3)[_ ]+qr[^{}]*)\|[ ]*(?:qualified|qualification)[ ]*=[ ]*[a-z0-9][a-z0-9]*[ ]*((?:\|[ ]*rows[ ]*=[ 0-9]*|)\|[ ]*competition[ ]*=)[ ]*/g, '$1$2 Qualification for ');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+(?:ha|cl3)[_ ]+qr[^{}]*)\|[ ]*(?:relegated|relegation)[ ]*=[ ]*[a-z0-9][a-z0-9]*[ ]*((?:\|[ ]*rows[ ]*=[ 0-9]*|)\|[ ]*competition[ ]*=)[ ]*/g, '$1$2 Relegation to ');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+(?:ha|cl3)[_ ]+qr(?:\{\{[^{}]*\}\}|[^{}])*)\|[ ]*nt[ ]*=[ ]*([0-9][0-9,]*)[ ]*(\}\})/g, '$1 <sup>$2</sup>$3');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+(?:ha|cl3)[_ ]+qr(?:\{\{[^{}]*\}\}|[^{}])*)\|[ ]*bc[ ]*=[ ]*transparent[^\|]*(\||\}\})/g, '$1$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*\|[ ]*w[ ]*=[ ]*)(\||\}\})/g, '$1-$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*\|[ ]*d[ ]*=[ ]*)(\||\}\})/g, '$1-$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*\|[ ]*l[ ]*=[ ]*)(\||\}\})/g, '$1-$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*\|[ ]*gf[ ]*=[ ]*)(\||\}\})/g, '$1-$2');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*\|[ ]*ga[ ]*=[ ]*)(\||\}\})/g, '$1-$2');
s = s.replace(/<(?:\{\{subst:void\}\}|)!-- P FB UNSUBST: -->[\t ]*[\r\n]*(\{\{[_ ]*[Ffb])/g, '$1');
for (var kk=25; kk>1; kk--) {
var r1 = new RegExp('(\\{\\{[_ ]*[Ff]b[_ ]+(?:ha|cl3)[_ ]+qr[^{}]*\\|[ ]*rows[ ]*=[ ]*)' + kk + '([ ]*(?:\\|[^{}]*|)\\}\\})[\\t ]*[\\r\\n]*[\\t ]*(\\{\\{[Ff]b[_ ]+cl2?[_ ]+team(?:\\{\\{[^{}]*\\}\\}|[^{}])*\\}\\})[\\t ]*[\\r\\n]', 'g');
s = s.replace(r1, '$1$2\n$3\n$1'+(kk-1)+'$2\n');
var r1 = new RegExp('(\\{\\{[_ ]*[Ff]b[_ ]+(?:ha|cl3)[_ ]+qr[^{}]*\\|[ ]*rows[ ]*=[ ]*)' + kk + '([ ]*(?:\\|[^{}]*|)\\}\\})[\\t ]*[\\r\\n]*((?:\\{\\{[Ff]b[_ ]+cl[_ ]+hth(?:\\{\\{[^{}]*\\}\\}|[^{}])*\\}\\}[\\t ]*[\\r\\n]|)[\\t ]*\\{\\{[Ff]b[_ ]+cl2?[_ ]+team(?:\\{\\{[^{}]*\\}\\}|[^{}])*\\}\\})[\\t ]*[\\r\\n]', 'g');
s = s.replace(r1, '$1$2\n$3\n$1'+(kk-1)+'$2\n');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+(?:ha|cl3)[_ ]+qr[^{}]*)\|rows[ ]*=[ ]*1?[ ]*(\||\}\})/g, '$1$2');
s = s.replace(/\{\{[_ ]*[Ff]b[_ ]+cl[_ ]+hth[_ ]*\}\}[\s]*[\r\n]/g, '');
}
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team(?:\{\{[^{}]*\}\}|[^{}])*(?:[^{}]|\{\{[^{}]*\}\})*)(\}\}[\t ]*[\r\n]*[\t ]*\{\{[_ ]*[Ff]b[_ ]+(?:ha|cl3)[_ ]+qr)/g, '$1|bc=inherit$2');
s = s.replace(/(\|[ ]*bc[ ]*=[^\|\{\}]*)\|[ ]*bc[ ]*=[ ]*inherit/g, '$1');
for (var kk=1; kk<100; kk++) {
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl[_ ]+hth[^{}]*\}\}[\t ]*[\r\n])(\{\{[_ ]*[Ff]b[_ ]+cl[23]?[_ ]+(?:team|qr)[^{}]*\}\}[\t ]*[\r\n])/g, '$2$1');
s = s.replace(/(\{\{[_ ]*[Ff]b[_ ]+cl[_ ]+hth[^{}]*\}\}[\t ]*[\r\n])(\{\{[_ ]*[Ff]b[_ ]+cl[23]?[_ ]+(?:team|qr)[^{}]*\}\}[\t ]*[\r\n])/g, '$2$1');
var r1 = new RegExp('(<!-- FB POS) '+kk+'-->[\\t ]*[\\r\\n]*[\\t ]*[\\r\\n]*\\{\\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team[_ ]*\\|[\\t ]*t[\\t ]*=[\\t ]*((?:\\[\\[[^\\[\\]]*\\]\\]|\\{\\{[^{}]*\\}\\}|[^\\[\\]\\{\\}\\|])*)[\\t ]*\\|[\\t ]*w[\\t ]*=[\\t ]*([0-9–\\?]+)[\\t ]*\\|[\\t ]*d[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*\\|[\\t ]*l[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*\\|[\\t ]*gf[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*\\|[\\t ]*ga[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*(\\}\\}|\|)', 'g');
s = s.replace(r1, '|team'+kk+'='+kk+'|name_'+kk+'=$2\n|win_'+kk+'=$3|draw_'+kk+'=$4|loss_'+kk+'=$5|gf_'+kk+'=$6|ga_'+kk+'=$7\n$1 '+(kk+1)+'-->');
r1 = new RegExp('(<!-- FB POS) '+kk+'-->[\\t ]*[\\r\\n]*[\\t ]*[\\r\\n]*\\{\\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team[_ ]*\\|[\\t ]*p[\\t ]*=[\\t ]*([0-9–]+|\\{\\{(?:gold1|silver2|bronze3)\\}\\})[\\t ]*\\|[\\t ]*group[\\t ]*=[\\t ]*((?:\\[\\[[^\\[\\]]*\\]\\]|\{\{[^{}]*\}\}|[\\-–—0-9A-Za-z\\?])*)[\\t ]*\\|[\\t ]*t[\\t ]*=[\\t ]*((?:\\[\\[[^\\[\\]]*\\]\\]|\\{\\{[^{}]*\\}\\}|[^\\[\\]\\{\\}\\|])*)[\\t ]*\\|[\\t ]*w[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*\\|[\\t ]*d[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*\\|[\\t ]*l[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*\\|[\\t ]*gf[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*\\|[\\t ]*ga[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*(\\}\\}|\|)', 'g');
s = s.replace(r1, '|team'+kk+'='+kk+'|pos_'+kk+'=$2|group_'+kk+'=$3|name_'+kk+'=$4\n|win_'+kk+'=$5|draw_'+kk+'=$6|loss_'+kk+'=$7|gf_'+kk+'=$8|ga_'+kk+'=$9\n$1 '+(kk+1)+'-->');
r1 = new RegExp('(<!-- FB POS) '+kk+'-->[\\t ]*[\\r\\n]*[\\t ]*[\\r\\n]*\\{\\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team[_ ]*\\|[\\t ]*group[\\t ]*=[\\t ]*((?:\\[\\[[^\\[\\]]*\\]\\]|[\\-–—0-9A-Za-z\\?])*)[\\t ]*\\|[\\t ]*t[\\t ]*=[\\t ]*((?:\\[\\[[^\\[\\]]*\\]\\]|\\{\\{[^{}]*\\}\\}|[^\\[\\]\\{\\}\\|])*)[\\t ]*\\|[\\t ]*w[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*\\|[\\t ]*d[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*\\|[\\t ]*l[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*\\|[\\t ]*gf[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*\\|[\\t ]*ga[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*(\\}\\}|\|)', 'g');
s = s.replace(r1, '|team'+kk+'='+kk+'|group_'+kk+'=$2|name_'+kk+'=$3\n|win_'+kk+'=$4|draw_'+kk+'=$5|loss_'+kk+'=$6|gf_'+kk+'=$7|ga_'+kk+'=$8\n$1 '+(kk+1)+'-->');
r1 = new RegExp('(<!-- FB POS) '+kk+'-->[\\t ]*[\\r\\n]*[\\t ]*[\\r\\n]*\\{\\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team[_ ]*\\|[\\t ]*p[\\t ]*=[\\t ]*((?:\\[\\[[^\\[\\]]*\\]\\]|[\\-–—=0-9A-Za-z\\?]|\\{\\{(?:gold1|silver2|bronze3)\\}\\})*)[\\t ]*\\|[\\t ]*t[\\t ]*=[\\t ]*((?:\\[\\[[^\\[\\]]*\\]\\]|\\{\\{[^{}]*\\}\\}|[^\\[\\]\\{\\}\\|])*)[\\t ]*\\|[\\t ]*w[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*\\|[\\t ]*d[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*\\|[\\t ]*l[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*\\|[\\t ]*gf[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*\\|[\\t ]*ga[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*\\|[\\t ]*tf[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*(\\}\\}|\|)', 'g');
s = s.replace(r1, '|team'+kk+'='+kk+'|pos_'+kk+'=$2|name_'+kk+'=$3\n|win_'+kk+'=$4|draw_'+kk+'=$5|loss_'+kk+'=$6|gf_'+kk+'=$7|ga_'+kk+'=$8|tf_'+kk+'=$9\n$1 '+(kk+1)+'-->');
r1 = new RegExp('(<!-- FB POS) '+kk+'-->[\\t ]*[\\r\\n]*[\\t ]*[\\r\\n]*\\{\\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team[_ ]*\\|[\\t ]*p[\\t ]*=[\\t ]*((?:\\[\\[[^\\[\\]]*\\]\\]|[\\-–—=0-9A-Za-z\\?]|\\{\\{(?:gold1|silver2|bronze3)\\}\\})*)[\\t ]*\\|[\\t ]*t[\\t ]*=[\\t ]*((?:\\[\\[[^\\[\\]]*\\]\\]|\\{\\{[^{}]*\\}\\}|[^\\[\\]\\{\\}\\|])*)[\\t ]*\\|[\\t ]*w[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*\\|[\\t ]*d[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*\\|[\\t ]*l[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*\\|[\\t ]*gf[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*\\|[\\t ]*ga[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*(\\}\\}|\|)', 'g');
s = s.replace(r1, '|team'+kk+'='+kk+'|pos_'+kk+'=$2|name_'+kk+'=$3\n|win_'+kk+'=$4|draw_'+kk+'=$5|loss_'+kk+'=$6|gf_'+kk+'=$7|ga_'+kk+'=$8\n$1 '+(kk+1)+'-->');
r1 = new RegExp('(<!-- FB POS) '+kk+'-->[\\t ]*[\\r\\n]*[\\t ]*[\\r\\n]*\\{\\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team[_ ]*\\|[\\t ]*p[\\t ]*=[\\t ]*((?:\\[\\[[^\\[\\]]*\\]\\]|[\\-–—=0-9A-Za-z\\?]|\\{\\{(?:gold1|silver2|bronze3)\\}\\})*)[\\t ]*\\|[\\t ]*t[\\t ]*=[\\t ]*((?:\\[\\[[^\\[\\]]*\\]\\]|\\{\\{[^{}]*\\}\\}|[^\\[\\]\\{\\}\\|])*)[\\t ]*\\|[\\t ]*pld[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*\\|[\\t ]*gf[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*\\|[\\t ]*ga[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*(\\}\\}|\|)', 'g');
s = s.replace(r1, '|team'+kk+'='+kk+'|pos_'+kk+'=$2|name_'+kk+'=$3\n|win_'+kk+'=–|draw_'+kk+'=–|loss_'+kk+'=–|gf_'+kk+'=$5|ga_'+kk+'=$6\n|matches_'+kk+'=$4\n$1 '+(kk+1)+'-->');
r1 = new RegExp('(<!-- FB POS) '+kk+'-->[\\t ]*[\\r\\n]*[\\t ]*[\\r\\n]*\\{\\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team[_ ]*\\|[\\t ]*t[\\t ]*=[\\t ]*((?:\\[\\[[^\\[\\]]*\\]\\]|\\{\\{[^{}]*\\}\\}|[^\\[\\]\\{\\}\\|])*)[\\t ]*\\|[\\t ]*w[\\t ]*=[\\t ]*([0-9–]+)[\\t ]*\\|[\\t ]*l[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*\\|[\\t ]*[pg]f[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*\\|[\\t ]*[pg]a[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*(\\}\\}|\|)', 'g');
s = s.replace(r1, '|team'+kk+'='+kk+'|name_'+kk+'=$2\n|win_'+kk+'=$3|loss_'+kk+'=$4|gf_'+kk+'=$5|ga_'+kk+'=$6\n$1 '+(kk+1)+'-->');
r1 = new RegExp('(<!-- FB POS) '+kk+'-->[\\t ]*[\\r\\n]*[\\t ]*[\\r\\n]*\\{\\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team[_ ]*\\|[\\t ]*group[\\t ]*=[\\t ]*((?:\\[\\[[^\\[\\]]*\\]\\]|[\\-–—0-9A-Za-z\\?])*)[\\t ]*\\|[\\t ]*t[\\t ]*=[\\t ]*((?:\\[\\[[^\\[\\]]*\\]\\]|\\{\\{[^{}]*\\}\\}|[^\\[\\]\\{\\}\\|])*)[\\t ]*\\|[\\t ]*w[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*\\|[\\t ]*l[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*\\|[\\t ]*[pg]f[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*\\|[\\t ]*[pg]a[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*(\\}\\}|\|)', 'g');
s = s.replace(r1, '|team'+kk+'='+kk+'|group_'+kk+'=$2|name_'+kk+'=$3\n|win_'+kk+'=$4|loss_'+kk+'=$5|gf_'+kk+'=$6|ga_'+kk+'=$7\n$1 '+(kk+1)+'-->');
r1 = new RegExp('(<!-- FB POS) '+kk+'-->[\\t ]*[\\r\\n]*[\\t ]*[\\r\\n]*\\{\\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team[_ ]*\\|[\\t ]*p[\\t ]*=[\\t ]*((?:\\[\\[[^\\[\\]]*\\]\\]|[\\-–—=0-9A-Za-z\\?]|\\{\\{(?:gold1|silver2|bronze3)\\}\\})*)[\\t ]*\\|[\\t ]*t[\\t ]*=[\\t ]*((?:\\[\\[[^\\[\\]]*\\]\\]|\\{\\{[^{}]*\\}\\}|[^\\[\\]\\{\\}\\|])*)[\\t ]*\\|[\\t ]*w[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*\\|[\\t ]*l[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*\\|[\\t ]*[pg]f[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*\\|[\\t ]*[pg]a[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*(\\}\\}|\|)', 'g');
s = s.replace(r1, '|team'+kk+'='+kk+'|pos_'+kk+'=$2|name_'+kk+'=$3\n|win_'+kk+'=$4|loss_'+kk+'=$5|gf_'+kk+'=$6|ga_'+kk+'=$7\n$1 '+(kk+1)+'-->');
r1 = new RegExp('(<!-- FB POS) '+kk+'-->[\\t ]*[\\r\\n]*[\\t ]*[\\r\\n]*\\{\\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team[_\\t ]*\\|[\\t ]*t[\\t ]*=[\\t ]*((?:\\[\\[[^\\[\\]]*\\]\\]|\\{\\{[^{}]*\\}\\}|[^\\[\\]\\{\\}\\|])*)[\\t ]*\\|[\\t ]*w[\\t ]*=[\\t ]*([\\-0-9–\\?]+)\\|[\\t ]*ow[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*\\|[\\t ]*ol[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*\\|[\\t ]*l[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*\\|[\\t ]*gf[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*\\|[\\t ]*ga[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*(\\}\\}|\|)', 'g');
s = s.replace(r1, '|team'+kk+'='+kk+'|pos_'+kk+'='+kk+'|name_'+kk+'=$2\n|win_'+kk+'=$3|OTwin_'+kk+'=$4|OTloss_'+kk+'=$5|loss_'+kk+'=$6|gf_'+kk+'=$7|ga_'+kk+'=$8\n$1 '+(kk+1)+'-->');
r1 = new RegExp('(<!-- FB POS) '+kk+'-->[\\t ]*[\\r\\n]*[\\t ]*[\\r\\n]*\\{\\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team[_ ]*\\|[\\t ]*p[\\t ]*=[\\t ]*((?:\\[\\[[^\\[\\]]*\\]\\]|[\\-–—=0-9A-Za-z\\?]|\\{\\{(?:gold1|silver2|bronze3)\\}\\})*)[\\t ]*\\|[\\t ]*t[\\t ]*=[\\t ]*((?:\\[\\[[^\\[\\]]*\\]\\]|\\{\\{[^{}]*\\}\\}|[^\\[\\]\\{\\}\\|])*)[\\t ]*\\|[\\t ]*w[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*\\|[\\t ]*ow[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*\\|[\\t ]*ol[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*\\|[\\t ]*l[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*\\|[\\t ]*gf[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*\\|[\\t ]*ga[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*(\\}\\}|\|)', 'g');
s = s.replace(r1, '|team'+kk+'='+kk+'|pos_'+kk+'=$2|name_'+kk+'=$3\n|win_'+kk+'=$4|OTwin_'+kk+'=$5|OTloss_'+kk+'=$6|loss_'+kk+'=$7|gf_'+kk+'=$8|ga_'+kk+'=$9\n$1 '+(kk+1)+'-->');
r1 = new RegExp('(<!-- FB POS) '+kk+'-->[\\t ]*[\\r\\n]*[\\t ]*[\\r\\n]*\\{\\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team[_ ]*\\|[\\t ]*p[\\t ]*=[\\t ]*((?:\\[\\[[^\\[\\]]*\\]\\]|[\\-–—=0-9A-Za-z\\?]|\\{\\{(?:gold1|silver2|bronze3)\\}\\})*)[\\t ]*\\|[\\t ]*t[\\t ]*=[\\t ]*((?:\\[\\[[^\\[\\]]*\\]\\]|\\{\\{[^{}]*\\}\\}|[^\\[\\]\\{\\}\\|])*)[\\t ]*\\|[\\t ]*w[\\t ]*=[\\t ]*([\\-0-9–\\?]+)\\/([\\-0-9–\\?]+)[\\t ]*\\|[\\t ]*d[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*\\|[\\t ]*l[\\t ]*=[\\t ]*([\\-0-9–\\?]+)\\/([\\-0-9–\\?]+)[\\t ]*\\|[\\t ]*gf[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*\\|[\\t ]*ga[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*(\\}\\}|\|)', 'g');
s = s.replace(r1, '|team'+kk+'='+kk+'|pos_'+kk+'=$2|name_'+kk+'=$3\n|win_'+kk+'=$4|OTwin_'+kk+'=$5|draw_'+kk+'=$6|loss_'+kk+'=$7|OTloss_'+kk+'=$8|gf_'+kk+'=$9|ga_'+kk+'=$10\n$1 '+(kk+1)+'-->');
r1 = new RegExp('(<!-- FB POS) '+kk+'-->[\\t ]*[\\r\\n]*[\\t ]*[\\r\\n]*\\{\\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team[_ ]*\\|ha=y\\|[\\t ]*p[\\t ]*=[\\t ]*((?:\\[\\[[^\\[\\]]*\\]\\]|[\\-–—=0-9A-Za-z\\?]|\\{\\{(?:gold1|silver2|bronze3)\\}\\})*)[\\t ]*\\|[\\t ]*t[\\t ]*=[\\t ]*((?:\\[\\[[^\\[\\]]*\\]\\]|\\{\\{[^{}]*\\}\\}|[^\\[\\]\\{\\}\\|])*)[\\t ]*\\|[\\t ]*hw[\\t ]*=[\\t ]*([0-9–]+)[\\t ]*\\|[\\t ]*hd[\\t ]*=[\\t ]*([0-9–]+)[\\t ]*\\|[\\t ]*hl[\\t ]*=[\\t ]*([0-9–]+)[\\t ]*\\|[\\t ]*hgf[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*\\|[\\t ]*hga[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*\\|[\\t ]*aw[\\t ]*=[\\t ]*([0-9–]+)[\\t ]*\\|[\\t ]*ad[\\t ]*=[\\t ]*([0-9–]+)[\\t ]*\\|[\\t ]*al[\\t ]*=[\\t ]*([0-9–]+)[\\t ]*\\|[\\t ]*agf[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*\\|[\\t ]*aga[\\t ]*=[\\t ]*([\\-0-9–\\?]+)[\\t ]*(\\}\\}|\|)', 'g');
s = s.replace(r1, '|team'+kk+'='+kk+'|pos_'+kk+'=$2|name_'+kk+'=$3\n|hwin_'+kk+'=$4|hdraw_'+kk+'=$5|hloss_'+kk+'=$6|hgf_'+kk+'=$7|hga_'+kk+'=$8|awin_'+kk+'=$9|adraw_'+kk+'=$10|aloss_'+kk+'=$11|agf_'+kk+'=$12|aga_'+kk+'=$13\n$1 '+(kk+1)+'-->');
r1 = new RegExp('(<!-- FB POS) '+kk+'-->[\\t ]*[\\r\\n]*[\\t ]*[\\r\\n]*\\{\\{[_ ]*[Ff]b[_ ]+cl2[_ ]+team[_ ]*\\|[\\t ]*t[\\t ]*=[\\t ]*((?:\\[\\[[^\\[\\]]*\\]\\]|\\{\\{[^{}]*\\}\\}|[^\\[\\]\\{\\}\\|])*)[\\t ]*(\\}\\}|\|)', 'g');
s = s.replace(r1, '|team'+kk+'='+kk+'|name_'+kk+'=$2\n|win_'+kk+'= |draw_'+kk+'= |loss_'+kk+'= |gf_'+kk+'= |ga_'+kk+'= \n$1 '+(kk+1)+'-->');
for (var ki=0;ki<3; ki++) {
var r2 = new RegExp('[\\t \\r\\n]*(<!-- FB POS) '+(kk+1)+'-->[\\t \\|]*status_text_([SC])[\\t ]*=[\\t ]*([A-Za-z ,]*)[\\t \\|]*(\\||\\}\\})', 'g');
s = s.replace(r2, '|status_text_$2=$3\n$1 '+(kk+1)+'-->$4');
r2 = new RegExp('[\\t \\r\\n]*(<!-- FB POS) '+(kk+1)+'-->[\\t \\|]*status[\\t ]*=[\\t ]*([A-Z,]*)[\\t \\|]*(\\||\\}\\})', 'g');
s = s.replace(r2, '|status_'+kk+'=$2\n$1 '+(kk+1)+'-->$3');
r2 = new RegExp('[\\t \\r\\n]*(<!-- FB POS) '+(kk+1)+'-->[\\t \\|]*dp[\\t ]*=[\\t ]*([0-9\\.]+)[\\t ]*(\\||\\}\\})', 'g');
s = s.replace(r2, '|adjust_points_'+kk+'=-$2\n$1 '+(kk+1)+'-->$3');
r2 = new RegExp('[\\t \\r\\n]*(<!-- FB POS) '+(kk+1)+'-->[\\t \\|]*dp[\\t ]*=[\\t ]*\\-([0-9\\.]+)[\\t ]*(\\||\\}\\})', 'g');
s = s.replace(r2, '|adjust_points_'+kk+'=$2\n$1 '+(kk+1)+'-->$3');
r2 = new RegExp('[\\t \\r\\n]*(<!-- FB POS) '+(kk+1)+'-->[\\t \\|]*bp[\\t ]*=[\\t ]*([0-9\\.]+)[\\t ]*(\\||\\}\\})', 'g');
s = s.replace(r2, '|adjust_points_'+kk+'=$2\n$1 '+(kk+1)+'-->$3');
r2 = new RegExp('[\\t \\r\\n]*(<!-- FB POS) '+(kk+1)+'-->[\\t \\|]*bp[\\t ]*=[\\t ]*\\-([0-9\\.]+)[\\t ]*(\\||\\}\\})', 'g');
s = s.replace(r2, '|adjust_points_'+kk+'=-$2\n$1 '+(kk+1)+'-->$3');
r2 = new RegExp('[\\t \\r\\n]*(<!-- FB POS) '+(kk+1)+'-->[\\t \\|]*pn[\\t ]*=[\\t ]*((?:\\[\\[[^\\[\\]]*\\]\\]|\\{\\{[^{}]*\\}\\}|[^\\[\\]\\{\\}\\|])*)[\\t ]*(\\||\\}\\})', 'g');
s = s.replace(r2, '|hth_'+kk+'=$2\n$1 '+(kk+1)+'-->$3');
}
var r3 = new RegExp('[\\t \\r\\n]*(<!-- FB POS) '+(kk+1)+'-->[\\t \\|]*bc[\\t ]*=[\\t ]*([#A-Z0-9a-z][^\\|\\{\\}]*)[\\t \\|]*\\}\\}', 'g');
s = s.replace(r3, '\n|result'+kk+'=RESULT'+kk+'|col_RESULT'+kk+'=$2\n$1 '+(kk+1)+'-->');
r3 = new RegExp('[\\t \\r\\n]*(<!-- FB POS) '+(kk+1)+'-->[\\t \\|]*\\}\\}', 'g');
s = s.replace(r3, '\n$1 '+(kk+1)+'-->');
var r4 = new RegExp('(<!-- FB POS) '+(kk+1)+'-->[\\t ]*[\\r\\n]*[\\t ]*[\\r\\n]*\\{\\{[_ ]*[Ff]b[_ ]+(?:ha|cl3)[_ ]+qr[_ ]*\\|[\\t ]*competition[\\t ]*=[\\t ]*((?:[^\\{\\}]|\\{\\{[^\\{\\}]*\\}\\})*)\\}\\}', 'g');
s = s.replace(r4, '|text_RESULT'+kk+'=$2\n$1 '+(kk+1)+'-->');
r4 = new RegExp('(<!-- FB POS) '+(kk+1)+'-->[\\t ]*[\\r\\n]*[\\t ]*[\\r\\n]*\\{\\{[_ ]*[Ff]b[_ ]+cl[_ ]+break[_ ]*\\}\\}', 'g');
s = s.replace(r4, '|split'+kk+'=y\n$1 '+(kk+1)+'-->');
r4 = new RegExp('(<!-- FB POS) '+(kk+1)+'-->[\\t ]*[\\r\\n]*[\\t ]*[\\r\\n]*<!--[ ]*[Ss][Ee][Pp][^<>]*-->', 'g');
s = s.replace(r4, '$1 '+(kk+1)+'-->');
}
for (var kh=0; kh<5; kh++) {
s = s.replace(/(<!-- FB POS [0-9–]+-->)[\t ]*[\r\n]*[\t ]*\{\{[_ ]*[Ff]b[_ ]+cl2?[_ ]+hth[^{}\|]*\|[ ]*hth[ ]*=[ ]*([^{}\|]*)\}\}/g, '|hth_=$2\n$1');
s = s.replace(/(\|hth_)=[ ]*([A-Z][^ \r\n\|\{\}:;]*)/g, '$1$2=$2');
}
s = s.replace(/\|[ ]*pos_([0-9]+)[ ]*=[ ]*\1[ ]*\|/g, '|');
s = s.replace(/<!-- FB POS [0-9–]+-->[\t ]*[\r\n]*[\t ]*[\r\n]*\{\{[_ ]*[Ff][b][_ ]+cl2?[_ ]+footer[^{}\|]*/g, '|update=complete\n|source=\n|class_rules=1) points; 2) goal difference; 3) number of goals scored.\n<!-- FB FOOTER -->');
s = s.replace(/<!-- FB POS [0-9–]+-->[\t ]*[\r\n]*[\t ]*[\r\n]*\{\{end\}\}/g, '\n|update=complete|source=\n}' + '}');
for (var kf=0; kf<5; kf++) {
s = s.replace(/(<!-- FB FOOTER -->)\|[ ]*hth[ ]*=[ ]*[a-z]+[ ]*(\||\}\}|[\r\n])/g, '\n|class_rules=1) points; 2) head-to-head points; 3) head-to-head goal difference; 4) head-to-head goals scored; 5) goal difference; 6) number of goals scored.\n$1$2');
s = s.replace(/(<!-- FB FOOTER -->)\|[ ]*gavg[ ]*=[ ]*[a-z]+[ ]*(\||\}\}|[\r\n])/g, '\n|class_rules=1) points; 2) goal ratio.\n$1$2');
s = s.replace(/(<!-- FB FOOTER -->)\|[ ]*wins[ ]*=[ ]*[a-z]+[ ]*(\||\}\}|[\r\n])/g, '\n|class_rules=1) points; 2) number of wins; 3) head-to-head points; 4) head-to-head goal difference; 5) head-to-head goals scored; 6) goal difference; 7) number of goals scored.\n$1$2');
s = s.replace(/(<!-- FB FOOTER -->)[\t ]*[\r\n]*[\t ]*(\|[ ]*s)[ ]*(=(?:\{\{[^\{\}]*\}\}|\[http[^\[\]]*\]|\[\[[^\[\]]*\]\]|[^\{\}\|\[\]])*)/g, '$2ource$3\n$1');
s = s.replace(/(<!-- FB FOOTER -->)[\t ]*[\r\n]*[\t ]*(\|[ ]*u)[ ]*(=(?:\{\{[^\{\}]*\}\}|\[http[^\[\]]*\]|\[\[[^\[\]]*\]\]|[^\{\}\|\[\]])*)/g, '$2pdate$3\n$1');
s = s.replace(/(<!-- FB FOOTER -->)[\t ]*[\r\n]*[\t ]*(\|[ ]*)orfc[ ]*(=(?:\{\{[^\{\}]*\}\}|\[http[^\[\]]*\]|\[\[[^\[\]]*\]\]|[^\{\}\|\[\]])*)/g, '\n$2class_rules$3\n$1');
s = s.replace(/(<!-- FB FOOTER -->)[\t ]*[\r\n]*[\t ]*\|[\t ]*season_over[\t ]*=[a-z\t \r\n]*(\||\}\})/g, '$1$2');
s = s.replace(/(<!-- FB FOOTER -->)[\t ]*[\r\n]*[\t ]*\|[\t ]*date[\t ]*=[A-Za-z,0-9\t \r\n]*(\||\}\})/g, '$1$2');
s = s.replace(/(<!-- FB FOOTER -->)[\t ]*[\r\n]*[\t ]*\|[\t ]*other[\t ]*=(?:[\t ]| )*(\||\}\})/g, '$1$2');
s = s.replace(/(<!-- FB FOOTER -->)[\t ]*[\r\n]*[\t ]*\|[\t ]*nt[\t ]*=[\t ]*[\r\n]*[\t ]*(\||\}\})/g, '$1$2');
s = s.replace(/(<!-- FB FOOTER -->)[\t ]*[\r\n]*[\t ]*(\|[\t ]*nt[\t ]*=(?:\[\[[^\[\]]*\]\]|\{\{[^{}]*\}\}|[^\[\]\{\}\|]|[\r\n])*)(\||\}\})/g, '\n$2\n$1$3');
s = s.replace(/(<!-- FB FOOTER -->)[\t\|\r\n ]*(\}\})/g, '$2');
}
lt = '';
while(lt != s) {
lt = s;
s = s.replace(/[\t ]*[\r\n][\t ]*([\r\n]\|[ ]*(?:res_col_header|class_rules|update)[ ]*=)/g, '$1');
s = s.replace(/(\|[ ]*(?:update|source)[ ]*=[^\r\n]*[\r\n])(\|[ ]*class_rules[ ]*=[^\r\n]*[\r\n])([\s]*\||[\s]*\}\})/g, '$2$1$3');
s = s.replace(/(\|[ ]*source[ ]*=[^\r\n]*[\r\n])(\|[ ]*(?:update|class_rules)[ ]*=[^\r\n]*[\r\n])([\s]*\||[\s]*\}\})/g, '$2$1$3');
s = s.replace(/\|[ ]*res_col_header[ ]*=[ ]*[^\|\{\}\r\n]*[\r\n]([^{}]*\|[ ]*res_col_header[ ]*=)/g, '$1');
s = s.replace(/\|[ ]*class_rules[ ]*=[ ]*[^\|\{\}\r\n]*[\r\n]([^{}]*\|[ ]*class_rules[ ]*=)/g, '$1');
s = s.replace(/\|[ ]*source[ ]*=[ ]*[\r\n]([^{}]*\|[ ]*source[ ]*=)/g, '$1');
s = s.replace(/\|[ ]*update[ ]*=[ ]*complete[ ]*[\r\n]([^{}]*\|[ ]*update[ ]*=)/g, '$1');
}
s = s.replace(/(\|[ ]*hth_[^=\|\[\]\{\}]*=[^\|\[\]\{\}\r\n]*)(\|[ ]*status_[^=\|\[\]\{\}]*=[^\|\[\]\{\}\r\n]*)(\|[^\r\n]*[\r\n]|[\r\n])/g, '$2$1$3');
s = s.replace(/([^\r\n])(\|[ ]*hth_[^=\|\[\]\{\}]*=[^\|\[\]\{\}\r\n]*)(\|[^\r\n]*[\r\n]|[\r\n])/g, '$1\n$3$2\n');
lt = '';
while(lt != s) {
lt = s;
s = s.replace(/([\r\n])(\|[ ]*(?:text_|bwin_|win_|hwin_|hth_|adjust_points_|matches_|result[0-9]+|split[0-9]+)[^\r\n]*[\r\n])[\t ]*[\r\n]*(\|[ ]*team[0-9]+[^\r\n]*[\r\n])/gm, '$1$3$2');
s = s.replace(/([\r\n])(\|[ ]*(?:text_|hth_|adjust_points|matches_|result[0-9]+)[^\r\n]*[\r\n])[\t ]*[\r\n]*(\|[ ]*(?:bwin_|win_|hwin_|split[0-9]+)[^\r\n]*[\r\n])/gm, '$1$3$2');
s = s.replace(/([\r\n])(\|[ ]*(?:text_|result[0-9]+)[^\r\n]*[\r\n])[\t ]*[\r\n]*(\|[ ]*(?:hth_|adjust_points_|matches_)[^\r\n]*[\r\n])/gm, '$1$3$2');
s = s.replace(/([\r\n])(\|[ ]*(?:bwin_|win_|hwin_)[^\r\n]*[\r\n])[\t ]*[\r\n]*(\|[ ]*(?:split[0-9]+)[^\r\n]*[\r\n])/gm, '$1$3$2');
}
s = s.replace(/(\|[ ]*result[0-9]+[ ]*=[ ]*)(RESULT[0-9]+)[ ]*[\r\n]*[ ]*(\|[ ]*col_)\2([ ]*=[^\r\n\|]*[\r\n]*[ ]*\|[ ]*text_)\2([ ]*=[^\r\n]*[\r\n])/g, '$3$2$4$2$5$1$2');
s = s.replace(/(\|[ ]*result[0-9]+[ ]*=[ ]*)(RESULT[0-9]+)[ ]*[\r\n]*[ ]*(\|[ ]*col_)\2([ ]*=[^\r\n\|]*)[\r\n]*/g, '$3$2$4|text_$2=\n$1$2');
s = s.replace(/([^\r\n])(\|[\t ]*col_)/g, '$1\n$2');
s = s.replace(/(\|[\t ]*col_[^\|]*)[\r\n]/g, '$1');
s = s.replace(/(\|[\t ]*team)([0-9]+[\t ]*=)/g, '$1<!-- FB MANGLE -->$2');
for (var kn=1; kn<100; kn++) {
var rr = new RegExp('\\|[ ]*name_' + kn + '[ ]*=([^\\r\\n]*)', 'g');
if(s.search(rr) >= 0 ) {
var nn = (s.match(rr))[0];
nn = nn.replace(rr, '$1');
nn = nn.replace(/^[\t ]*\{\{flagicon\|([A-Z][A-Z][A-Z])\}\}[\t ]*\[\[[^\[\]]*\]\][\t ]*–[\t ]*\[\[[^\[\]]*\]\]/gi, '$1');
nn = nn.replace(/^[\t ]*\{\{(?:AFL|SANFL) (W|S|N)(?:est|th)A\}\}/gi, '$1AD');
nn = nn.replace(/^[\t ]*\{\{(?:AFL|SANFL) WT\}\}/gi, 'WTO');
nn = nn.replace(/^[\t ]*\{\{(?:AFL|SANFL) ([^{}\|]*)\}\}/gi, '$1');
nn = nn.replace(/^[\t ]*\{\{[_ ]*[Ff]lag[A-Za-z0-9]*athlete[_ ]*\|(?:[^{}\|\[\]]|\[\[[^\[\]]*\]\])*\|[ ]*([A-Z]+)[ ]*(?:\|[^{}]*|)\}\}/g, '$1');
nn = nn.replace(/,[\t ]+(?:\[\[[^\[\]]*\]\]|[^\[\]\{\},]*)[ ]*$/g, '');
nn = nn.replace(/^[\t ]*\{\{[_ ]*[Ff]lagicon[^{}]*\}\}[\t ]*/g, '');
nn = nn.replace(/^[\t ]*\{\{[_ ]*[a-z][a-z]ca[_ ]*\}\}[\t ]*/g, '');
nn = nn.replace(/^[\t ]*\{\{[_ ]*(?:UAAPteam)[\t_ ]*\|([^{}\|]*)\|[^{}]*\}\}/g, '$1');
nn = nn.replace(/^[\t ]*\{\{[_ ]*(?:[Ww]p|[Bb]k|[Bb]eachsoccer|[Ii]i?hw?|[Hh]bw?[jy]?|[Rr][lu]|[Rr]h[mw]|[Bb]andy|[Vv]b|[Ff])[^{}\|]*\|([A-Z][A-Z][A-Z])[^{}]*\}\}/g, '$1');
nn = nn.replace(/^[\t ]*\{\{[_ ]*(?:[Ww]p|[Bb]k|[Bb]eachsoccer|[Ii]i?hw?|[Hh]bw?[jy]?|[Rr][lu]|[Rr]h[mw]|[Bb]andy|[Vv]b|[Ff])[^{}\|]*\|[^{}\|]*\|([A-Z][A-Z][A-Z])[^{}]*\}\}/g, '$1');
nn = nn.replace(/^[\t ]*\{\{[_ ]*(?:[Ww]p|[Bb]k|[Bb]eachsoccer|[Ii]i?hw?|[Hh]bw?[jy]?|[Rr][lu]|[Rr]h[mw]|[Bb]andy|[Vv]b|[Ff])[^{}\|]*\|([A-Z][^0-9\|\{\}]*)[^{}]*?\}\}/g, '$1');
nn = nn.replace(/^[\t ]*\{\{[_ ]*(?:[Ww]p|[Bb]k|[Bb]eachsoccer|[Ii]i?hw?|[Hh]bw?[jy]?|[Rr][lu]|[Rr]h[mw]|[Bb]andy|[Vv]b|[Ff])[^{}\|]*\|[^{}\|]*\|([A-Z][^0-9\|\{\}]*)[^{}]*?\}\}/g, '$1');
nn = nn.replace(/^[\t ]*\{\{[_ ]*([A-Z][A-Z])[_ ]*\}\}[ ]*$/g, '$1');
nn = nn.replace(/[\t ]*<ref[^<>\/]*>[^<>]*<\/ref>[\t ]*/g, '');
nn = nn.replace(/\[\[File:[^\[\]]*\]\][ ]*/g, '');
nn = nn.replace(/^[\t ]+/g, '');
nn = nn.replace(/[\t ]+$/g, '');
var lnt = nn.replace(/^\[\[([^\[\]\|]*)(?:|\|[^\[\]\|]*)\]\].*/g, '$1');
var lntnp = nn.replace(/\./g, '');
lnt = lnt.replace(/([\(\)\.\-])/g, '\\$1');
lntnp = lntnp.replace(/([\(\)\.\-])/g, '\\$1');
var ra1 = new RegExp('\\|[\\t ]*name_([^\\[\\]\\|\\{\\}<>0-9][^\\[\\]\\|\\{\\}<>0-9][^\\[\\]\\|\\{\\}<>]?)[\\t ]*=(?:\\{\\{[Ff]lagicon\\|[^{}]*\\}\\}|[\\t ])*\\[\\[[\\t ]*(?:' + lnt + '|' + lntnp + ')[\\t ]*(?:\\||\\]\\])', 'g');
var ra2 = new RegExp('\\|[\\t ]*name_([^\\[\\]\\|\\{\\}<>0-9][^\\[\\]\\|\\{\\}<>][^\\[\\]\\|\\{\\}<>][^\\[\\]\\|\\{\\}<>])[\\t ]*=[\\t ]*\\[\\[[\\t ]*(?:' + lnt + '|' + lntnp + ')[\\t ]*(?:\\||\\]\\])', 'g');
var ra3 = new RegExp('\\[\\[[\\t ]*(?:' + lnt + '|' + lntnp + ')[\\t ]*\\|([A-ZÁÀÂÄÃǍĀĂĄÅĆĈÇČĊĐĎÉÈÊËĚĒĔĖĘĜĢĞĠĤĦÍÌÎÏĨǏĪĬİĮĴĶĹĻĽŁŃÑŅŇÓÒÔÖÕǑŌŎǪŐŔŖŘŚŜŞŠȘŤÚÙÛÜŨŮǓŪŬŲŰŴÝŶŸȲŹŽŻÆǢØŒÐÞƏ0-9][^\\[\\]\\|\\{\\}<>]?[A-ZÁÀÂÄÃǍĀĂĄÅĆĈÇČĊĐĎÉÈÊËĚĒĔĖĘĜĢĞĠĤĦÍÌÎÏĨǏĪĬİĮĴĶĹĻĽŁŃÑŅŇÓÒÔÖÕǑŌŎǪŐŔŖŘŚŜŞŠȘŤÚÙÛÜŨŮǓŪŬŲŰŴÝŶŸȲŹŽŻÆǢØŒÐÞƏ0-9])\\]\\]', 'g');
var ra4 = new RegExp('\\[\\[[\\t ]*(?:' + lnt + '|' + lntnp + ')[\\t ]*\\|([A-ZÁÀÂÄÃǍĀĂĄÅĆĈÇČĊĐĎÉÈÊËĚĒĔĖĘĜĢĞĠĤĦÍÌÎÏĨǏĪĬİĮĴĶĹĻĽŁŃÑŅŇÓÒÔÖÕǑŌŎǪŐŔŖŘŚŜŞŠȘŤÚÙÛÜŨŮǓŪŬŲŰŴÝŶŸȲŹŽŻÆǢØŒÐÞƏ0-9][^\\[\\]\\|\\{\\}<>][^\\[\\]\\|\\{\\}<>][A-ZÁÀÂÄÃǍĀĂĄÅĆĈÇČĊĐĎÉÈÊËĚĒĔĖĘĜĢĞĠĤĦÍÌÎÏĨǏĪĬİĮĴĶĹĻĽŁŃÑŅŇÓÒÔÖÕǑŌŎǪŐŔŖŘŚŜŞŠȘŤÚÙÛÜŨŮǓŪŬŲŰŴÝŶŸȲŹŽŻÆǢØŒÐÞƏ0-9])\\]\\]', 'g');
var ra5 = new RegExp('\\[\\[[\\t ]*(?:' + lnt + '|' + lntnp + ')[\\t ]*\\|([^\\[\\]\\|\\{\\}<>][^\\[\\]\\|\\{\\}<>][^\\[\\]\\|\\{\\}<>]?)\\]\\]', 'g');
var ra6 = new RegExp('([A-Z][A-Z][A-Z][0-9]?)[ \\t ]*\\[\\[[\\t ]*(?:' + lnt + '|' + lntnp + ')[\\t ]*(?:\\||\\]\\])', 'g');
var abb = nn.replace(/^\[\[(?:[^\[\]\|]*\||)([^\[\]\|]*)\]\]/g, '$1');
if (abb.search(/^[\t ]*[A-ZÁÀÂÄÃǍĀĂĄÅĆĈÇČĊĐĎÉÈÊËĚĒĔĖĘĜĢĞĠĤĦÍÌÎÏĨǏĪĬİĮĴĶĹĻĽŁŃÑŅŇÓÒÔÖÕǑŌŎǪŐŔŖŘŚŜŞŠȘŤÚÙÛÜŨŮǓŪŬŲŰŴÝŶŸȲŹŽŻÆǢØŒÐÞƏ][A-ZÁÀÂÄÃǍĀĂĄÅĆĈÇČĊĐĎÉÈÊËĚĒĔĖĘĜĢĞĠĤĦÍÌÎÏĨǏĪĬİĮĴĶĹĻĽŁŃÑŅŇÓÒÔÖÕǑŌŎǪŐŔŖŘŚŜŞŠȘŤÚÙÛÜŨŮǓŪŬŲŰŴÝŶŸȲŹŽŻÆǢØŒÐÞƏ][A-ZÁÀÂÄÃǍĀĂĄÅĆĈÇČĊĐĎÉÈÊËĚĒĔĖĘĜĢĞĠĤĦÍÌÎÏĨǏĪĬİĮĴĶĹĻĽŁŃÑŅŇÓÒÔÖÕǑŌŎǪŐŔŖŘŚŜŞŠȘŤÚÙÛÜŨŮǓŪŬŲŰŴÝŶŸȲŹŽŻÆǢØŒÐÞƏ][\t ]*$/) >=0) {
abb = abb.replace(/^[\t ]*([A-ZÁÀÂÄÃǍĀĂĄÅĆĈÇČĊĐĎÉÈÊËĚĒĔĖĘĜĢĞĠĤĦÍÌÎÏĨǏĪĬİĮĴĶĹĻĽŁŃÑŅŇÓÒÔÖÕǑŌŎǪŐŔŖŘŚŜŞŠȘŤÚÙÛÜŨŮǓŪŬŲŰŴÝŶŸȲŹŽŻÆǢØŒÐÞƏ][A-ZÁÀÂÄÃǍĀĂĄÅĆĈÇČĊĐĎÉÈÊËĚĒĔĖĘĜĢĞĠĤĦÍÌÎÏĨǏĪĬİĮĴĶĹĻĽŁŃÑŅŇÓÒÔÖÕǑŌŎǪŐŔŖŘŚŜŞŠȘŤÚÙÛÜŨŮǓŪŬŲŰŴÝŶŸȲŹŽŻÆǢØŒÐÞƏ][A-ZÁÀÂÄÃǍĀĂĄÅĆĈÇČĊĐĎÉÈÊËĚĒĔĖĘĜĢĞĠĤĦÍÌÎÏĨǏĪĬİĮĴĶĹĻĽŁŃÑŅŇÓÒÔÖÕǑŌŎǪŐŔŖŘŚŜŞŠȘŤÚÙÛÜŨŮǓŪŬŲŰŴÝŶŸȲŹŽŻÆǢØŒÐÞƏ])[\t ]*$/g, '$1');
} else if (f.search(ra1) >= 0) {
abb = (f.match(ra1))[0];
abb = abb.replace(ra1, '$1');
} else if (f.search(ra2) >= 0) {
abb = (f.match(ra2))[0];
abb = abb.replace(ra2, '$1');
} else if (f.search(ra3) >= 0) {
abb = (f.match(ra3))[0];
abb = abb.replace(ra3, '$1');
abb = abb.toUpperCase();
} else if (f.search(ra4) >= 0) {
abb = (f.match(ra4))[0];
abb = abb.replace(ra4, '$1');
abb = abb.toUpperCase();
} else if (f.search(ra5) >= 0) {
abb = (f.match(ra5))[0];
abb = abb.replace(ra5, '$1');
abb = abb.toUpperCase();
} else if (ts.search(ra1) >= 0) {
abb = (ts.match(ra1))[0];
abb = abb.replace(ra1, '$1');
} else if (f.search(ra2) >= 0) {
abb = (ts.match(ra2))[0];
abb = abb.replace(ra2, '$1');
} else if (ts.search(ra3) >= 0) {
abb = (ts.match(ra3))[0];
abb = abb.replace(ra3, '$1');
abb = abb.toUpperCase();
} else if (ts.search(ra4) >= 0) {
abb = (ts.match(ra4))[0];
abb = abb.replace(ra4, '$1');
abb = abb.toUpperCase();
} else if (ts.search(ra5) >= 0) {
abb = (ts.match(ra5))[0];
abb = abb.replace(ra5, '$1');
abb = abb.toUpperCase();
} else if (f.search(ra6) >= 0) {
abb = (f.match(ra6))[0];
abb = abb.replace(ra6, '$1');
abb = abb.toUpperCase();
} else {
abb = abb.replace(/<!-- UNLINK -->/g, '');
abb = abb.replace(/[ ]*<sup>[^<>]*<\/sup>[ ]*/g, '');
abb = abb.replace(/[ ]*\{\{ref[^{}]*\}\}/gi, '');
abb = abb.replace(/^[\t ]*([^ ]*) [Cc]lub[\t ]*$/g, '$1');
abb = abb.replace(/^[\t ]*(?:Sporting|Atlético|União|[AF]\.?[KC]\.?|[CK]\.?F\.?|[SCU]\.?D\.?|S\.?C\.?|GDR?|S[RG]|CDA?|UDR?|AD|CA)[\t ]+/g, '');
abb = abb.replace(/[\t ]+(?:Sporting|Atlético|[AF]\.?[CK]\.?|[CK]\.?F\.?|[SCU]\.?D\.?|S\.?C\.?|GDR?)[\t ]*$/g, '');
abb = abb.replace(/[\t ]+(?:[AF]\.?C\.?|[CK]\.?F\.?|[SCU]\.?D\.?|S\.?C\.?|GDR?)[\t ]+/g, ' ');
abb = abb.replace(/^[\t ]*[Aa][Ll][\t \-][\t ]*/g, '');
abb = abb.replace(/^[\t ]*[Tt][Hh][Ee][\t ]+/g, '');
abb = abb.replace(/[\t ]+[Oo][Ff][\t ]+/g, ' ');
abb = abb.replace(/[\t ]+[d][aoe][\t ]+/g, ' ');
abb = abb.replace(/([a-z])([A-Z])/g, '$1 $2');
abb = abb.replace(/\./g, '');
abb = abb.replace(/[\(\)\-]/g, ' ');
abb = abb.replace(/^Club[ ]+/gi, '');
abb = abb.replace(/^[\t ]*\{\{([A-Z][A-Z][A-Z])\}\}[\t ]*$/gi, '$1');
abb = abb.replace(/^[\t ]*\{\{AFL ([A-Z][A-Z]*)\}\}[\t ]*$/gi, '$1');
abb = abb.replace(/^([A-ZÁÀÂÄÃǍĀĂĄÅĆĈÇČĊĐĎÉÈÊËĚĒĔĖĘĜĢĞĠĤĦÍÌÎÏĨǏĪĬİĮĴĶĹĻĽŁŃÑŅŇÓÒÔÖÕǑŌŎǪŐŔŖŘŚŜŞŠȘŤÚÙÛÜŨŮǓŪŬŲŰŴÝŶŸȲŹŽŻÆǢØŒÐÞƏ])[^ ]*[\t ]+([A-Z][A-Z][A-Z])$/g, '$1$2');
abb = abb.replace(/^([A-ZÁÀÂÄÃǍĀĂĄÅĆĈÇČĊĐĎÉÈÊËĚĒĔĖĘĜĢĞĠĤĦÍÌÎÏĨǏĪĬİĮĴĶĹĻĽŁŃÑŅŇÓÒÔÖÕǑŌŎǪŐŔŖŘŚŜŞŠȘŤÚÙÛÜŨŮǓŪŬŲŰŴÝŶŸȲŹŽŻÆǢØŒÐÞƏ])[^ ]*[\t ]+([A-Z])o([A-Z][A-Z]])$/g, '$1$2$3');
abb = abb.replace(/^(IFK)[\t ]+([A-ZÁÀÂÄÃǍĀĂĄÅĆĈÇČĊĐĎÉÈÊËĚĒĔĖĘĜĢĞĠĤĦÍÌÎÏĨǏĪĬİĮĴĶĹĻĽŁŃÑŅŇÓÒÔÖÕǑŌŎǪŐŔŖŘŚŜŞŠȘŤÚÙÛÜŨŮǓŪŬŲŰŴÝŶŸȲŹŽŻÆǢØŒÐÞƏ])[^ ]*$/g, '$1$2');
abb = abb.replace(/^([A-ZÁÀÂÄÃǍĀĂĄÅĆĈÇČĊĐĎÉÈÊËĚĒĔĖĘĜĢĞĠĤĦÍÌÎÏĨǏĪĬİĮĴĶĹĻĽŁŃÑŅŇÓÒÔÖÕǑŌŎǪŐŔŖŘŚŜŞŠȘŤÚÙÛÜŨŮǓŪŬŲŰŴÝŶŸȲŹŽŻÆǢØŒÐÞƏ][A-ZÁÀÂÄÃǍĀĂĄÅĆĈÇČĊĐĎÉÈÊËĚĒĔĖĘĜĢĞĠĤĦÍÌÎÏĨǏĪĬİĮĴĶĹĻĽŁŃÑŅŇÓÒÔÖÕǑŌŎǪŐŔŖŘŚŜŞŠȘŤÚÙÛÜŨŮǓŪŬŲŰŴÝŶŸȲŹŽŻÆǢØŒÐÞƏ]) ([A-ZÁÀÂÄÃǍĀĂĄÅĆĈÇČĊĐĎÉÈÊËĚĒĔĖĘĜĢĞĠĤĦÍÌÎÏĨǏĪĬİĮĴĶĹĻĽŁŃÑŅŇÓÒÔÖÕǑŌŎǪŐŔŖŘŚŜŞŠȘŤÚÙÛÜŨŮǓŪŬŲŰŴÝŶŸȲŹŽŻÆǢØŒÐÞƏ0-9])[^ ]*$/g, '$1$2');
abb = abb.replace(/^([A-ZÁÀÂÄÃǍĀĂĄÅĆĈÇČĊĐĎÉÈÊËĚĒĔĖĘĜĢĞĠĤĦÍÌÎÏĨǏĪĬİĮĴĶĹĻĽŁŃÑŅŇÓÒÔÖÕǑŌŎǪŐŔŖŘŚŜŞŠȘŤÚÙÛÜŨŮǓŪŬŲŰŴÝŶŸȲŹŽŻÆǢØŒÐÞƏ])[^ ]* ([A-ZÁÀÂÄÃǍĀĂĄÅĆĈÇČĊĐĎÉÈÊËĚĒĔĖĘĜĢĞĠĤĦÍÌÎÏĨǏĪĬİĮĴĶĹĻĽŁŃÑŅŇÓÒÔÖÕǑŌŎǪŐŔŖŘŚŜŞŠȘŤÚÙÛÜŨŮǓŪŬŲŰŴÝŶŸȲŹŽŻÆǢØŒÐÞƏ0-9][A-ZÁÀÂÄÃǍĀĂĄÅĆĈÇČĊĐĎÉÈÊËĚĒĔĖĘĜĢĞĠĤĦÍÌÎÏĨǏĪĬİĮĴĶĹĻĽŁŃÑŅŇÓÒÔÖÕǑŌŎǪŐŔŖŘŚŜŞŠȘŤÚÙÛÜŨŮǓŪŬŲŰŴÝŶŸȲŹŽŻÆǢØŒÐÞƏ0-9])$/g, '$1$2');
abb = abb.replace(/^([A-ZÁÀÂÄÃǍĀĂĄÅĆĈÇČĊĐĎÉÈÊËĚĒĔĖĘĜĢĞĠĤĦÍÌÎÏĨǏĪĬİĮĴĶĹĻĽŁŃÑŅŇÓÒÔÖÕǑŌŎǪŐŔŖŘŚŜŞŠȘŤÚÙÛÜŨŮǓŪŬŲŰŴÝŶŸȲŹŽŻÆǢØŒÐÞƏ])[^ ]* ([A-ZÁÀÂÄÃǍĀĂĄÅĆĈÇČĊĐĎÉÈÊËĚĒĔĖĘĜĢĞĠĤĦÍÌÎÏĨǏĪĬİĮĴĶĹĻĽŁŃÑŅŇÓÒÔÖÕǑŌŎǪŐŔŖŘŚŜŞŠȘŤÚÙÛÜŨŮǓŪŬŲŰŴÝŶŸȲŹŽŻÆǢØŒÐÞƏ0-9])[^ ]* ([A-ZÁÀÂÄÃǍĀĂĄÅĆĈÇČĊĐĎÉÈÊËĚĒĔĖĘĜĢĞĠĤĦÍÌÎÏĨǏĪĬİĮĴĶĹĻĽŁŃÑŅŇÓÒÔÖÕǑŌŎǪŐŔŖŘŚŜŞŠȘŤÚÙÛÜŨŮǓŪŬŲŰŴÝŶŸȲŹŽŻÆǢØŒÐÞƏ0-9])[^ ]*$/g, '$1$2$3');
abb = abb.replace(/^([A-ZÁÀÂÄÃǍĀĂĄÅĆĈÇČĊĐĎÉÈÊËĚĒĔĖĘĜĢĞĠĤĦÍÌÎÏĨǏĪĬİĮĴĶĹĻĽŁŃÑŅŇÓÒÔÖÕǑŌŎǪŐŔŖŘŚŜŞŠȘŤÚÙÛÜŨŮǓŪŬŲŰŴÝŶŸȲŹŽŻÆǢØŒÐÞƏ])[^ ]* ([A-ZÁÀÂÄÃǍĀĂĄÅĆĈÇČĊĐĎÉÈÊËĚĒĔĖĘĜĢĞĠĤĦÍÌÎÏĨǏĪĬİĮĴĶĹĻĽŁŃÑŅŇÓÒÔÖÕǑŌŎǪŐŔŖŘŚŜŞŠȘŤÚÙÛÜŨŮǓŪŬŲŰŴÝŶŸȲŹŽŻÆǢØŒÐÞƏ][a-záàâäãǎāăąåćĉçčċđďéèêëěēĕėęĝģğġĥħíìîïĩǐīĭiįĵķĺļľłńñņňóòôöõǒōŏǫőŕŗřśŝşšșťúùûüũůǔūŭųűŵýŷÿȳźžżæǣøœðþə])[^ ]*$/g, '$1$2');
abb = abb.replace(/[\. ]/g, '');
abb = abb.replace(/^([A-ZÁÀÂÄÃǍĀĂĄÅĆĈÇČĊĐĎÉÈÊËĚĒĔĖĘĜĢĞĠĤĦÍÌÎÏĨǏĪĬİĮĴĶĹĻĽŁŃÑŅŇÓÒÔÖÕǑŌŎǪŐŔŖŘŚŜŞŠȘŤÚÙÛÜŨŮǓŪŬŲŰŴÝŶŸȲŹŽŻÆǢØŒÐÞƏ][a-záàâäãǎāăąåćĉçčċđďéèêëěēĕėęĝģğġĥħíìîïĩǐīĭiįĵķĺļľłńñņňóòôöõǒōŏǫőŕŗřśŝşšșťúùûüũůǔūŭųűŵýŷÿȳźžżæǣøœðþə][a-záàâäãǎāăąåćĉçčċđďéèêëěēĕėęĝģğġĥħíìîïĩǐīĭiįĵķĺļľłńñņňóòôöõǒōŏǫőŕŗřśŝşšșťúùûüũůǔūŭųűŵýŷÿȳźžżæǣøœðþə]).*$/g, '$1');
abb = abb.toUpperCase();
// abb = abb.replace(/^([^ \.])[ ]*([^ \.])[ \.]*([^ ]).*/g, '$1$2$3'); // Remove this line!
abb = myPrompt('Team abbreviation for ' + nn.toUpperCase(), abb, false);
}
ra = new RegExp('\\|[ ]*name_' + abb + '[ ]*=', 'g');
var modflag = 0;
while(s.search(ra) >= 0) {
abb = myPrompt(abb + ' already exists!\nTeam abbreviation for ' + nn, abb+'2', false);
if (abb.search(/2$/) >= 0) {
abb = abb.replace(/2$/g, '');
rr = new RegExp('(\\|[ ]*(?:OT|PK|win[345]|loss[345]|)[a-z][a-z]*_)' + abb + '([ ]*=)', 'g');
s=s.replace(rr, '$1' + abb + '1$2');
rr = new RegExp('(\\|[ ]*adjust_points_)' + abb + '([ ]*=)', 'g');
s=s.replace(rr, '$1' + abb + '1$2');
rr = new RegExp('(\\|[ ]*team(?:<!-- FB MANGLE -->|)[0-9]+[ ]*=[ ]*)' + abb + '([\\t ]*\\||[\\t ]*[\r\n])', 'g');
s=s.replace(rr, '$1' + abb + '1$2');
abb = abb + '2'
modflag = modflag + 1;
}
ra = new RegExp('\\|[ ]*name_' + abb + '[ ]*=', 'g');
}
rr = new RegExp('(\\|[ ]*(?:OT|PK|win[345]|loss[345]|)[a-z][a-z]*_)' + kn + '([ ]*=)', 'g');
s=s.replace(rr, '$1' + abb + '$2');
rr = new RegExp('(\\|[ ]*match[1-9]?_)' + kn + '(_[^_= ]+(?:_note|)[ ]*=)', 'g');
s=s.replace(rr, '$1' + abb + '$2');
rr = new RegExp('(\\|[ ]*match[1-9]?_[^_= ]+_)' + kn + '((?:_note|)[ ]*=)', 'g');
s=s.replace(rr, '$1' + abb + '$2');
rr = new RegExp('(\\|[ ]*adjust_points_)' + kn + '([ ]*=)', 'g');
s=s.replace(rr, '$1' + abb + '$2');
rr = new RegExp('(\\|[ ]*team(?:<!-- FB MANGLE -->|)[0-9]+[ ]*=[ ]*)' + kn + '([\\t ]*\\||[\\t ]*[\r\n])', 'g');
s=s.replace(rr, '$1' + abb + '$2');
if(modflag > 0) {
abb = abb.replace(/2$/g, '');
rr = new RegExp('(\\|[ ]*name_' + abb + '[0-9]+[ ]*=[^\\r\\n]*)', 'g')
var alist = s.match(rr);
for (var ka=0; ka< alist.length; ka++) {
var abbo = alist[ka].replace(/^\|[ ]*name_([^= ]*)[ ]*=.*$/g, '$1');
abb = myPrompt(alist.join('\n'), abbo, false)
rr = new RegExp('(\\|[ ]*(?:OT|PK|win[345]|loss[345]|)[a-z][a-z]*_)' + abbo + '([ ]*=)', 'g');
s=s.replace(rr, '$1' + abb + '$2');
rr = new RegExp('(\\|[ ]*adjust_points_)' + abbo + '([ ]*=)', 'g');
s=s.replace(rr, '$1' + abb + '$2');
rr = new RegExp('(\\|[ ]*team(?:<!-- FB MANGLE -->|)[0-9]+[ ]*=[ ]*)' + abbo + '([\\t ]*\\||[\\t ]*[\r\n])', 'g');
s=s.replace(rr, '$1' + abb + '$2');
}
}
}
}
s = s.replace(/<!-- FB MANGLE -->/g, '');
s = s.replace(/\[\[([^\[\]\|]*)\]\]<!-- UNLINK -->/g, '$1');
var rlist = s.match(/\|[ ]*text_RESULT([0-9]+)[ ]*=/g);
if(rlist) {
for (var kr=0; kr < rlist.length; kr++) {
rlist[kr] = rlist[kr].replace(/\|[ ]*text_RESULT([0-9]+)[ ]*=/g, '$1');
}
for (var ki=0; ki < rlist.length; ki++) {
for(var kj = ki+1; kj < rlist.length; kj++) {
var rr = new RegExp('\\|[ ]*col_RESULT' + rlist[ki] + '[ ]*=[ ]*([^ \\r\\n\\|]*)[ ]*\\|[ ]*text_RESULT' + rlist[ki] + '[ ]*=[ ]*((?:\\{\\{[^{}]*\\}\\}|\\[\\[[^\\[\\]]*\\]\\]|[^\\{\\}\\[\\]\\|])*)[\\r\\n]((?:\\|[ ]*result[0-9]+[ ]*=[ ]*RESULT' + rlist[ki] + '| )*)\\|[ ]*result([0-9]+)[ ]*=[ ]*RESULT' + rlist[ki] + '[ ]*((?:\\||[\\r\\n])(?:\\{\\{[^{}]*\\}\\}|[^{}])*)\\|[ ]*col_RESULT' + rlist[kj] + '[ ]*=[ ]*\\1[ ]*\\|[ ]*text_RESULT' + rlist[kj] + '[ ]*=[ ]*\\2[ ]*[\\r\\n]*\\|[ ]*result([0-9]+)[ ]*=[ ]*RESULT' + rlist[kj] + '[ ]*(\\||[\\r\\n])');
s = s.replace(rr, '|col_RESULT' + rlist[ki] + '=$1|text_RESULT' + rlist[ki] + '=$2\n$3|result$4=RESULT' + rlist[ki] + '|result$6=RESULT' + rlist[ki] + '$5$7');
s = s.replace(/[\t ]*[\r\n][\t ]*([\r\n]\|[ ]*(?:col_|result[0-9]+|text_))/g, '$1');
}
}
}
for (var kn=1; kn<100; kn++) {
var rr = new RegExp('\\|[ ]*text_RESULT' + kn + '[ ]*=([^\\r\\n]*)', 'g');
if(s.search(rr) >= 0 ) {
var nn = (s.match(rr))[0];
nn = nn.replace(rr, '$1');
nn = nn.replace(/\{\{nowrap\|([^{}]*)\}\}/gi, '$1');
var abb = nn.replace(/^\[\[(?:[^\[\]\|]*\||)([^\[\]\|]*)\]\]/g, '$1');
abb = abb.replace(/[\t \|]*$/g, '');
abb = abb.replace(/ /gi, ' ');
abb = abb.replace(/^Qualified for the.*play\-offs[\] ]*$/g, 'QP');
abb = abb.replace(/^Qualified for the.*play\-offs[\] ]*, then promoted.*$/g, 'QPP');
abb = abb.replace(/^Reprieved from relegation$/i, 'RR');
abb = abb.replace(/^Relegat.*Division One South.*/, 'R1S');
abb = abb.replace(/^Relegat.*Division One North.*/, 'R1N');
abb = abb.replace(/^Relegat.*Third Division South.*/, 'R3S');
abb = abb.replace(/^Relegat.*Third Division North.*/, 'R3N');
abb = abb.replace(/^Relegat.*Essex Senior League.*/, 'RESL');
abb = abb.replace(/^Relegat.*Southern Counties East League.*/, 'RSCEL');
abb = abb.replace(/^Relegat.*Sussex County League.*/, 'RSCL');
abb = abb.replace(/^Relegation Playoffs[ ]*[\-–][ ]*Relegated.*/, 'RPR');
abb = abb.replace(/^Relegat[a-z]* Play.*/i, 'RP');
abb = abb.replace(/^Promotion Playoffs[ ]*[\-–][ ]*Promoted.*/, 'PPP');
abb = abb.replace(/^Promot[a-z]* Play.*/i, 'PP');
abb = abb.replace(/^Relegat.*/, 'R');
abb = abb.replace(/^Promot.*/, 'P');
abb = abb.replace(/^Re\-Elected.*/i, 'RE');
abb = abb.replace(/^Not Re\-Elected.*/i, 'NRE');
abb = abb.replace(/^.*Champions League(?:<br[^<>]*>|[\t ]|First)*group stage.*/gi, 'CLGS');
abb = abb.replace(/^.*Champions League(?:<br[^<>]*>|[\t ])*Third.*/gi, 'CL3');
abb = abb.replace(/^.*Champions League(?:<br[^<>]*>|[\t ])*Second.*/gi, 'CL2');
abb = abb.replace(/^.*Champions League(?:<br[^<>]*>|[\t ])*First.*/gi, 'CL1');
abb = abb.replace(/^.*Champions League(?:<br[^<>]*>|[\t ])*Play\-?off.*/gi, 'CLPR');
abb = abb.replace(/^.*Euro[a-z]* League(?:<br[^<>]*>|[\t ]|First)*group stage.*/gi, 'ELGS');
abb = abb.replace(/^.*Euro[a-z]* League(?:<br[^<>]*>|[\t ])*Third.*/gi, 'EL3');
abb = abb.replace(/^.*Euro[a-z]* League(?:<br[^<>]*>|[\t ])*Second.*/gi, 'EL2');
abb = abb.replace(/^.*Euro[a-z]* League(?:<br[^<>]*>|[\t ])*First.*/gi, 'EL1');
abb = abb.replace(/^.*Euro[a-z]* League(?:<br[^<>]*>|[\t ])*Play\-?off.*/gi, 'ELPR');
abb = abb.replace(/^.*Euro[a-z]* Cup Winners' Cup(?:<br[^<>]*>|[\t ])*Third.*/gi, 'ECWC3');
abb = abb.replace(/^.*Euro[a-z]* Cup Winners' Cup(?:<br[^<>]*>|[\t ])*Second.*/gi, 'ECWC2');
abb = abb.replace(/^.*Euro[a-z]* Cup Winners' Cup(?:<br[^<>]*>|[\t ])*First.*/gi, 'ECWC1');
abb = abb.replace(/^.*Euro[a-z]* Cup(?:<br[^<>]*>|[\t ])*Third.*/gi, 'EC3');
abb = abb.replace(/^.*Euro[a-z]* Cup(?:<br[^<>]*>|[\t ])*Second.*/gi, 'EC2');
abb = abb.replace(/^.*Euro[a-z]* Cup(?:<br[^<>]*>|[\t ])*First.*/gi, 'EC1');
abb = abb.replace(/^.*UEFA Cup Winners' Cup(?:<br[^<>]*>|[\t ])*Third.*/gi, 'CWC3');
abb = abb.replace(/^.*UEFA Cup Winners' Cup(?:<br[^<>]*>|[\t ])*Second.*/gi, 'CWC2');
abb = abb.replace(/^.*UEFA Cup Winners' Cup(?:<br[^<>]*>|[\t ])*First.*/gi, 'CWC1');
abb = abb.replace(/^.*UEFA Cup(?:<br[^<>]*>|[\t ])*Qual.*/gi, 'UCQR');
abb = abb.replace(/^.*UEFA Cup(?:<br[^<>]*>|[\t ])*Third.*/gi, 'UC3');
abb = abb.replace(/^.*UEFA Cup(?:<br[^<>]*>|[\t ])*Second.*/gi, 'UC2');
abb = abb.replace(/^.*UEFA Cup(?:<br[^<>]*>|[\t ])*First.*/gi, 'UC1');
abb = abb.replace(/^.*Intertoto Cup(?:<br[^<>]*>|[\t ])*Third.*/gi, 'IC3');
abb = abb.replace(/^.*Intertoto Cup(?:<br[^<>]*>|[\t ])*Second.*/gi, 'IC2');
abb = abb.replace(/^.*Intertoto Cup(?:<br[^<>]*>|[\t ])*First.*/gi, 'IC1');
abb = abb.replace(/^.*Inter\-?Cities Fairs Cup(?:<br[^<>]*>|[\t ])*First.*/gi, 'ICF1');
abb = abb.replace(/^.*Inter\-?Cities Fairs Cup(?:<br[^<>]*>|[\t ])*Second.*/gi, 'ICF2');
abb = abb.replace(/^.*[0-9] ([A-Z])[^ \-]*[ \-]([A-Z])[^ \-]*[ \-]([A-Z])[^ \-]*[ \-]([A-Z])[^ \-]*$/g, '$1$2$3$4');
abb = abb.replace(/^.*[0-9] ([A-Z])[^ \-]*[ \-]([A-Z])[^ \-]*[ \-]([A-Z])[^ \-]*$/g, '$1$2$3');
abb = abb.replace(/^.*[0-9] ([A-Z])[^ \-]*[ \-]([A-Z])[^ \-]*$/g, '$1$2');
abb = abb.replace(/^([A-Z])[^ \-]*[ \-]([A-Z])[^ \-]*[ \-]([A-Z])[^ \-]*[ \-]([A-Z])[^ \-]*$/g, '$1$2$3$4');
abb = abb.replace(/^([A-Z])[^ \-]*[ \-]([A-Z])[^ \-]*[ \-]([A-Z])[^ \-]*$/g, '$1$2$3');
abb = abb.replace(/^([A-Z])[^ \-]*[ \-]([A-Z])[^ \-]*$/g, '$1$2');
abb = abb.replace(/^Qualifi.*[Cc]hampionship [Pp]lay.*/i, 'QCP')
abb = abb.replace(/^Relegation[ ]*Play.*/, 'RP')
abb = abb.replace(/^Relegat.*/i, 'R')
abb = abb.replace(/^Promot.*/i, 'P')
abb = abb.replace(/^Qualifi.*/i, 'Q')
abb = abb.replace(/^Withdr.*/i, 'WD')
abb = abb.replace(/^Joined[\t ]+/i, 'J')
abb = abb.replace(/.* ([A-Z])[^ \|\[\]]* ([A-Z0-9])[^ \|\[\]]* ([A-Z0-9])[^ \|\[\]]* ([A-Z0-9])[^ \|\[\]]*$/, '$1$2$3$4');
abb = abb.replace(/.* ([A-Z])[^ \|\[\]]* ([A-Z0-9])[^ \|\[\]]* ([A-Z0-9])[^ \|\[\]]*$/, '$1$2$3');
abb = abb.toUpperCase();
if (abb == '') {
ra = new RegExp('\\|[ ]*col_RESULT' + kn + '[ ]*=[ ]*green1', 'gi');
if(s.search(ra) >=0) {
abb = 'A';
}
ra = new RegExp('\\|[ ]*col_RESULT' + kn + '[ ]*=[ ]*yellow1', 'gi');
if(s.search(ra) >=0) {
abb = 'B';
}
ra = new RegExp('\\|[ ]*col_RESULT' + kn + '[ ]*=[ ]*blue1', 'gi');
if(s.search(ra) >=0) {
abb = 'C';
}
ra = new RegExp('\\|[ ]*col_RESULT' + kn + '[ ]*=[ ]*red1', 'gi');
if(s.search(ra) >=0) {
abb = 'E';
}
ra = new RegExp('\\|[ ]*col_RESULT' + kn + '[ ]*=[ ]*lavender', 'gi');
if(s.search(ra) >=0) {
abb = 'O';
}
ra = new RegExp('\\|[ ]*col_RESULT' + kn + '[ ]*=[ ]*#ddffdd', 'gi');
if(s.search(ra) >=0) {
abb = 'EC';
}
ra = new RegExp('\\|[ ]*col_RESULT' + kn + '[ ]*=[ ]*#E6E6FA', 'gi');
if(s.search(ra) >=0) {
abb = 'CWC';
}
ra = new RegExp('\\|[ ]*col_RESULT' + kn + '[ ]*=[ ]*#fffacd', 'gi');
if(s.search(ra) >=0) {
abb = 'UC';
}
ra = new RegExp('\\|[ ]*col_RESULT' + kn + '[ ]*=[ ]*#ACE1AF', 'gi');
if(s.search(ra) >=0) {
abb = 'C';
}
ra = new RegExp('\\|[ ]*col_RESULT' + kn + '[ ]*=[ ]*#(?:ffecc0|b0c4de)', 'gi');
if(s.search(ra) >=0) {
abb = 'PP';
}
ra = new RegExp('\\|[ ]*col_RESULT' + kn + '[ ]*=[ ]*#ecd1ff', 'gi');
if(s.search(ra) >=0) {
abb = 'TRFR';
}
ra = new RegExp('\\|[ ]*col_RESULT' + kn + '[ ]*=[ ]*#(?:a8dca8|FFFF99|ff9[^0-9a-f])', 'gi');
if(s.search(ra) >=0) {
abb = 'P';
}
ra = new RegExp('\\|[ ]*col_RESULT' + kn + '[ ]*=[ ]*#D0F0C0', 'gi');
if(s.search(ra) >=0) {
abb = 'CP';
}
ra = new RegExp('\\|[ ]*col_RESULT' + kn + '[ ]*=[ ]*(?:moccasin|#(?:d2e6ff|FFE4B5))', 'gi');
if(s.search(ra) >=0) {
abb = 'PP';
}
ra = new RegExp('\\|[ ]*col_RESULT' + kn + '[ ]*=[ ]*#FBCEB1', 'gi');
if(s.search(ra) >=0) {
abb = 'PPP';
}
ra = new RegExp('\\|[ ]*col_RESULT' + kn + '[ ]*=[ ]*#90EE90', 'gi');
if(s.search(ra) >=0) {
abb = 'QP';
}
ra = new RegExp('\\|[ ]*col_RESULT' + kn + '[ ]*=[ ]*#FFF380', 'gi');
if(s.search(ra) >=0) {
abb = 'Q3';
}
ra = new RegExp('\\|[ ]*col_RESULT' + kn + '[ ]*=[ ]*#(?:ffd1d1|FFE6E6)', 'gi');
if(s.search(ra) >=0) {
abb = 'RP';
}
ra = new RegExp('\\|[ ]*col_RESULT' + kn + '[ ]*=[ ]*#(?:deb0b0|FFCCCC|fcc|ff9696)', 'gi');
if(s.search(ra) >=0) {
abb = 'R';
}
ra = new RegExp('\\|[ ]*col_RESULT' + kn + '[ ]*=[ ]*#(?:cfc|ccffcc)', 'gi');
if(s.search(ra) >=0) {
abb = 'A';
}
ra = new RegExp('\\|[ ]*col_RESULT' + kn + '[ ]*=[ ]*gold', 'gi');
if(s.search(ra) >=0) {
abb = '1ST';
}
ra = new RegExp('\\|[ ]*col_RESULT' + kn + '[ ]*=[ ]*silver', 'gi');
if(s.search(ra) >=0) {
abb = '2ND';
}
}
ra = new RegExp('\\|[ ]*col_RESULT' + kn + '[ ]*=[ ]*([^ \|\r\n]+)', 'gi');
var cval = s.match(ra);
if (cval[1]) { cval = cval[1]; }
abb = myPrompt('Result abbreviation for (' + cval + ') ' + nn, abb, false);
ra = new RegExp('\\|[ ]*text_' + abb + '[ ]*=', 'g');
while(s.search(ra) >= 0) {
abb = myPrompt(abb + ' already exists!\nResult abbreviation for ' + nn, nn.replace(/^\[\[(?:[^\[\]\|]*\||)([^\[\]\|]*)\]\]/g, '$1'), false);
ra = new RegExp('\\|[ ]*text_' + abb + '[ ]*=', 'g');
}
rr = new RegExp('(\\|[ ]*[a-z][a-z]*_)RESULT' + kn + '([ ]*=)', 'g');
s = s.replace(rr, '$1' + abb + '$2');
rr = new RegExp('(\\|[ ]*note_res_)RESULT' + kn + '([ ]*=)', 'g');
s = s.replace(rr, '$1' + abb + '$2');
rr = new RegExp('(\\|[ ]*result[0-9]+[ ]*=[ ]*)RESULT' + kn + '([\\t ]*\\||[\\t ]*[\\r\\n])', 'g');
s = s.replace(rr, '$1' + abb + '$2');
s = s.replace(rr, '$1' + abb + '$2');
}
s = s.replace(/(\|[ ]*text_)([^= \|\r\n]*)([ ]*=[^\r\n<>]*)<sup>([^<>\r\n]*)<\/sup>/g, '$1$2$3\n|note_res_$2=$4');
s = s.replace(/(\|[ ]*text_)([^= \|\r\n]*)([ ]*=[^\r\n<>]*)(\{\{ref[^{}]*\}\})/g, '$1$2$3\n|note_res_$2=$4');
s = s.replace(/(\|[ ]*result[0-9]+[ ]*=[ ]*)([^ \[\]\|\r\n]*)[ ]*[\r\n](\|[ ]*result[0-9]+[ ]*=[ ]*)\2/g, '$1$2$3$2');
}
s = s.replace(/([^\r\n])(\|[ ]*class_rules[ ]*=)/g, '$1\n$2');
s = s.replace(/(\|[ ]*class_rules[ ]*=[^\r\n]*)([\r\n][^\{\}]*\}\})[\t ]*[\r\n]*[\t ]*[\r\n]*<sup>([^<>]*)<\/sup>[\t ]*[\r\n]/g, '$1<br>$3$2\n');
s = s.replace(/(\|[ ]*update[ ]*=[ ]*)([\r\n]|\||\}\})/g, '$1complete$2');
s = s.replace(/([^\r\n])(\|[ ]*update[ ]*=)/g, '$1\n$2');
s = s.replace(/(\|[ ]*source[ ]*=)[ ]*([\r\n]\}\}(?:<small>|[\t ])*?)[ ]*[Ss]ource[\t ]*:[\t ]*(\[http:[^\[\]]*\]|<[R][Ee][Ff][^<>\/]*[\/]>|<[Rr][Ee][Ff][^<>\/]*>[^<>]*<\/[Rr][Ee][Ff]>)[ ]*(<[Bb][Rr]|<\/small>|[\r\n])/g, '$1$3$2$4');
s = s.replace(/(\|[ ]*team)([0-9]+)([ ]*=[^\|]*\|[ ]*name_[^=]*=[^\r\n<>]*)[ ]*<ref group="note">([^<>]*)<\/ref>((?:[^{}]|[\r\n])*result)\2([ ]*=[ ]*)([A-Z0-9]+)[ ]*([\r\n]|\|)/g, '$1$2$3$5$2$6$7\n|note_res_$7=$4$8');
if (s.search(/res_col_header=RESCOLHEADER/g) >= 0) {
var PQR='';
if (s.search(/result[0-9]+[ ]*=[ ]*P[^A-Z]/g) >= 0) {
PQR=PQR+'P';
}
if (s.search(/result[0-9]+[ ]*=[ ]*(?:Q|P[A-Z]|A)/g) >= 0) {
PQR=PQR+'Q';
}
if (s.search(/result[0-9]+[ ]*=[ ]*R/g) >= 0) {
PQR=PQR+'R';
}
PQR = PQR.replace(/PQR/, 'PR');
PQR = myPrompt('Results column header?', PQR, true);
s = s.replace(/res_col_header=RESCOLHEADER/g, 'res_col_header=' + PQR);
}
s = s.replace(/(\}\})[ ]*\{\{small\|[ ]*Rules for classification: ([^<>\{\}]*)\}\}/g, '|class_rules=$2\n$1');
s = s.replace(/(\}\})[ ]*<small>[ ]*Rules for classification: ([^<>\{\}]*)<\/small>/g, '|class_rules=$2\n$1');
s = s.replace(/((?:color|text)_)<!-- MANGLE -->/g, '$1');
s = s.replace(/(\|team[0-9]+=[^\[\]\|\{\}]*[\r\n])(\|win_)/g, '$1\n$2');
s = s.replace(/(\|(?:status_|ga_)[^=]*=[^\[\]\|\{\}]*[\r\n])(\|(?:col_|hth_))/g, '$1\n$2');
s = s.replace(/(\|hth_[^=]*=[^\r\n]*[\r\n])(\|col_)/g, '$1\n$2');
s = s.replace(/(\|match_[^\r\n]*[\r\n])(\|(?:update|source|name_))/g, '$1\n$2');
s = s.replace(/[\s]*[\r\n][\t ]*[\r\n]/g, '\n\n');
if(s.search(/\|showpk[ ]*=[ ]*y[ ]*[\r\n]/g)>=0) {
s = s.replace(/\|showpk[ ]*=[ ]*y[ ]*[\r\n]/g, '');
s = s.replace(/(style=)WDL/g, '$1WL PK');
s = s.replace(/\|[ ]*draw(_[^=]*=)([0-9])([0-9])/g, '|PKwin$1$2|PKloss$1$3');
}
if(s.search(/\|win_[^=]*=[^\|\r\n]*\|OTwin_[^=]*=[^\|\r\n]*\|OTloss_[^=]*=[^\|\r\n]*\|loss_/g) >=0 ) {
s = s.replace(/(style=)WDL/g, '$1WL OT');
}
if(s.search(/<!-- FB PK OT -->/g) >= 0) {
s = s.replace(/<!-- FB PK OT -->[\t ]*[\r\n]*/g, '');
s = s.replace(/(\|[ ]*res_col_header[^\r\n]*[\r\n])/g, '$1|showOTloss=n|showPKwin=y\n|OTwinpoints=3|PKwinpoints=2\n\n|OTwin_header={'+'{Tooltip|W+|Won after extra time}'+'}\n|PKwin_header={'+'{Tooltip|W<small>P</small>|Won on penalties}'+'}\n');
s = s.replace(/\|[ ]*draw(_[^=]*=)([0-9])([0-9])/g, '|OTwin$1$2|PKwin$1$3');
}
s = s.replace(/(\|[ ]*source[ ]*=)[\t ]*[\r\n]*[\t ]*(\}\})[\t ]*[\r\n]*[\t ]*[\r\n]*[\t ]*(<ref[^<>]*\/>|<ref[^<>\/]*>[^<>]*<\/ref>)/g, '$1$3\n$2');
s = s.replace(/[\r\n]\|[ ]*res_col_header[ ]*=[ ]*[\r\n]/g, '\n');
s = s.replace(/(\|winpoints=4[\t ]*)([\r\n])/g, '$2$1');
s = s.replace(/(\|[ ]*status_text_P[^\r\n]*[\r\n])([^{}]*[\r\n])(\|col_)/g, '$2$1$3');
lt = '';
while(lt != s) {
lt = s;
s = s.replace(/(\|(?:matches|adjust_points)_[^=]*=[ ]*[\-0-9]+)[ ]*(\|status_[^=]*=[^\r\n]*)/g, '$2$1');
s = s.replace(/([=0-9][ ]*)(\|(?:matches|adjust_points)_[^=]*=[ \-]*[0-9])/g, '$1\n$2');
s = s.replace(/(\|(?:matches|adjust_points)_[^\r\n]*[\r\n])(\|win_[^\r\n]*[\r\n])/g, '$2$1');
}
s = s.replace(/(\|matches)(_[^=]*=)([\- 0-9]+)[\r\n](\|adjust_points)\2/g, '$1$2$3$4$2');
lt = '';
while(lt != s) {
lt = s;
s = s.replace(/(\|adjust_points)(_[^=]*=)([\- 0-9]+)[\r\n]*[\t ]*[\r\n](\|hth)\2/g, '$1$2$3$4$2');
s = s.replace(/(\|adjust_points)(_[^=]*=)([\- 0-9]+)[\r\n]((?:\|adjust_points_[^\r\n]*[\r\n]|[\t ]*[\r\n])*)(\|hth)\2([^\r\n]*[\r\n])/g, '$1$2$3$5$2$6$4');
}
if(s.search(/loss_before_draw[ ]*=[ ]*[ty]/g) >=0 ) {
s = s.replace(/(\|[ ]*draw_[^=]*=[0-9 ]*)(\|[ ]*loss_[^=]*=[0-9 ]*)/g, '$2$1');
}
if(s.search(/for_against_style[ ]*=[ ]*p/g) >=0 ) {
s = s.replace(/(\|[ ]*)g([fa]_[^=]*=)/g, '$1p$2');
}
if (s.search(/(?:<!-- FB |\{\{[_ ]*[Ff]b[_ ]*cl)/g) >= 0) {
alert(s);
return oldtext;
}
return s;
}
// -------------------------------------------------------------------------------- //
function wpUnlabel(s)
{
if (s.search(/<!--[\t ]*FB RELABEL[\t ]*-->/) >=0 ) {
var rlist = s.match(/\|[ ]*team[0-9]+[ ]*=[ ]*((?:[^\t\r\n\|\[\]]|\[\[[^\[\]]*\]\])+)/g);
for (var kr=0; kr < rlist.length; kr++) {
var n = rlist[kr].replace(/\|[ ]*team([0-9]+)[ ]*=[\t ]*((?:[^\t\r\n\|\[\]]|\[\[[^\[\]]*\]\])+)/g, '$1');
var a = rlist[kr].replace(/\|[ ]*team([0-9]+)[ ]*=[\t ]*((?:[^\t\r\n\|\[\]]|\[\[[^\[\]]*\]\])+)/g, '$2');
a = a.replace(/^[\s]*/g, '')
a = a.replace(/[\s]*$/g, '')
a = a.replace(/([\[\]\|])/g, '\\$1')
var r = new RegExp("(\\|[\\t ]*team" + n + "[\\t ]*=)[\\t ]*(?:[^\\t\\r\\n\\|\\[\\]]|\\[\\[[^\\[\\]]*\\]\\])+", "g");
s = s.replace(r, '$1' + n);
r = new RegExp("(\\|[\\t ]*(?:name|hwin|awin|OTwin|PKwin|win|hdraw|adraw|draw|OTloss|PKloss|hloss|aloss|loss|hgf|agf|gf|pf|hga|aga|ga|pa|tb|lb|adjust_points|hth|note|status|rw|group|match[0-9]?_[^_= ]+|short|bwin|bloss|swin|sloss|win[345]s|loss[345]s|sp?w|sp?l))_" + a + "([\t ]*=)", "g");
s = s.replace(r, '$1_' + n + '$2');
r = new RegExp("(\\|[\\t ]*(?:match[0-9]?))_" + a + "(_[^_= ]+(?:_note|)[\t ]*=)", "g");
s = s.replace(r, '$1_' + n + '$2');
r = new RegExp("(\\|[\\t ]*hth_[^=]*=[ ]*)" + a + "([\\t\\r\\n ]*(?:\\}|\\|))", "g");
s = s.replace(r, '$1' + n + '$2');
}
}
s = s.replace(/<!--[\t ]*FB RELABEL[\t ]*-->/g, '');
return s;
}
// -------------------------------------------------------------------------------- //
function wpUnpos(s,f)
{
var oldtext = s;
if(s.search(/\|[ ]*team1[ ]*=[ ]*[^\|\{\}\[\]]*\|[ ]*pos_[^=]*=[ ]*[0-9]+[ ]*\|/g) >= 0) {
var offsetstr = s.match(/\|[ ]*team1[ ]*=[ ]*[^\|\{\}\[\]]*\|[ ]*pos_[^=]*=[ ]*[0-9]+[ ]*\|/g)[0];
offsetstr = offsetstr.replace(/^.*pos_[^=]*=[ ]*([0-9]+)[ ]*\|$/g, '$1');
var offset = Number(offsetstr) - 1;
s = s.replace(/(\|[ ]*team1[ ]*=[ ]*[^\|\{\}\[\]]*\|[ ]*pos_[^=]*=[ ]*[0-9]+[ ]*\|)/g, '|highest_pos = ' + (offset+1) + '\n\n$1');
s = s.replace(/(\|[ ]*(?:team|result))([0-9]+)([ ]*=)/g, '$1{'+'{subst'+':#expr:'+offset+'+$2}'+'}$3');
var lt = '';
var i = 1;
while (lt != s) {
lt = s;
var rr = new RegExp('\\{\\{subst[ ]*:[ ]*#expr[ ]*:[ ]*' + offset + '[ ]*\\+[ ]*' + i + '[ ]*\\}\\}', 'gi');
s = s.replace(rr, offset + i);
i = i + 1;
}
s = s.replace(/(\|[ ]*team)([0-9]+)([ ]*=[^\|\{\}\[\]]*)\|[ ]*pos_[^=]*=[ ]*\2[ ]*(\|)/g, '$1$2$3$4');
}
if(s.search(/\|[ ]*pos_[^=]*=/g) >=0) {
alert(s);
return oldtext;
}
return s;
}
// -------------------------------------------------------------------------------- //
function wpFb()
{
var teamset = `
|name_AEL=[[AEL Limassol]]
|name_ALK=[[Alki Larnaca F.C.]]
|name_ALK=[[Alki Larnaca FC]]
|name_ANA=[[Anagennisi Deryneia]]
|name_ANR=[[Anorthosis Famagusta FC]]
|name_APE=[[APEP F.C.]]
|name_APEP=[[APEP Limassol]]
|name_APL=[[Apollon Limassol]]
|name_APN=[[APOEL F.C.]]
|name_APN=[[APOEL FC]]
|name_APP=[[APOP Paphos]]
|name_ARS=[[Aris Limassol F.C.]]
|name_CHA=[[Chalkanoras Idaliou]]
|name_DAM=[[Digenis Akritas Morphou]]
|name_ENP=[[Enosis Neon Paralimni FC]]
|name_EPA=[[EPA Larnaca FC]]
|name_ERM=[[Ermis Aradippou]]
|name_ETH=[[Ethnikos Achna FC]]
|name_EVA=[[Evagoras Paphos]]
|name_KER=[[Keravnos Strovolou FC]]
|name_LYS=[[ASIL Lysi]]
|name_NSL=[[Nea Salamis Famagusta FC]]
|name_OAR=[[Omonia Aradippou]]
|name_OLY=[[Olympiakos Nicosia]]
|name_OMO=[[AC Omonia]]
|name_POL=[[Pezoporikos Larnaca]]
|name_SAL=[[Nea Salamis FC]]
|name_ADI=[[Aditajs]]
|name_ALF=[[FK Alfa]]
|name_APG=[[Apgaismes Tehnika]]
|name_APG=[[FK Apgaismes tehnika]]
|name_AUD=[[FK Auda]]
|name_BET=[[Betons]]
|name_CEL=[[Celtnieks Daugavpils]]
|name_CEL=[[Celtnieks Rīga]]
|name_DAU=[[FC Daugava Riga]]
|name_DUB=[[Dubna]]
|name_DĪZ=[[Dīzelists]]
|name_ENE=[[Enerģija Rīga]]
|name_FAL=[[Faless]]
|name_GAU=[[Gauja Valmiera]]
|name_GTE=[[Gaismas Tehnika]]
|name_JAU=[[Jaunatnes izlase]]
|name_JUN=[[Junioru izlase]]
|name_JUR=[[Jurnieks]]
|name_JŪR=[[FK Jūrnieks]]
|name_KIM=[[Kimikis]]
|name_LAT=[[Latgale]]
|name_MAI=[[9 Maijs]]
|name_MAS=[[Masinbuvetajs]]
|name_OLI=[[FK Liepājas Metalurgs]]
|name_OST=[[Ostinieks]]
|name_PĀR=[[FK Pārdaugava]]
|name_RAF=[[RAF (football club)]]
|name_RAU=[[Rīgas Audums]]
|name_SAR=[[Sarkanais Kvadrāts]]
|name_SKO=[[Forums Skonto]]
|name_SKV=[[Sarkanais Kvadrats]]
|name_SME=[[Sarkanais Metalurgs]]
|name_STA=[[Starts]]
|name_STR=[[Strautmala]]
|name_TIL=[[Tiltubuvetajs]]
|name_TOR=[[Torpedo Rīga]]
|name_V-D=[[Varpa-Dilar]]
|name_VAR=[[Varpa]]
|name_VEF=[[FK VEF Rīga]]
|name_ZEM=[[Zemgale]]
|name_ZVE=[[Zvezda]]
|name_CEL=[[Celtnieks Rīga]]
|name_ELE=[[Elektrons Rīga]]
|name_ENE=[[Enerģija Rīga]]
|name_GAU=[[Gauja Valmiera]]
|name_JUR=[[Jurnieks]]
|name_KIM=[[Kimikis]]
|name_MET=[[Metalists]]
|name_PRO=[[Progress Rīga]]
|name_RAD=[[Radiotehnikis]]
|name_RPI=[[RPI Riga]]
|name_SME=[[Sarkanais Metalurgs]]
|name_STA=[[Starts]]
|name_TOR=[[Torpedo Rīga]]
|name_VEF=[[VEF]]
|name_AAB=[[AaB Fodbold]]
|name_AAC=[[Alemannia Aachen]]
|name_ABE=[[Aberdeen F.C.]]
|name_ACM=[[A.C. Milan]]
|name_AEK=[[AEK Athens F.C.]]
|name_AJX=[[AFC Ajax]]
|name_AMC=[[Amica Wronki]]
|name_AND=[[R.S.C. Anderlecht]]
|name_APO=[[APOEL FC]]
|name_ARI=[[Aris Thessaloniki F.C.]]
|name_ARS=[[Arsenal F.C.]]
|name_AST=[[Aston Villa F.C.]]
|name_ATH=[[Athletic Bilbao]]
|name_ATL=[[Atlético Madrid]]
|name_AUS=[[FK Austria Wien]]
|name_AUX=[[AJ Auxerre]]
|name_AZ =[[AZ (football club)]]
|name_AZ =[[AZ Alkmaar]]
|name_BAR=[[FC Barcelona]]
|name_BAY=[[FC Bayern Munich]]
|name_BDX=[[FC Girondins de Bordeaux]]
|name_BEN=[[S.L. Benfica]]
|name_BEV=[[K.S.K. Beveren]]
|name_BJK=[[Beşiktaş J.K.]]
|name_BLB=[[Blackburn Rovers F.C.]]
|name_BOL=[[Bolton Wanderers F.C.]]
|name_BRA=[[S.C. Braga]]
|name_BRA=[[SK Brann]]
|name_BRM=[[SV Werder Bremen]]
|name_BRU=[[Club Brugge K.V.]]
|name_BRU=[[Club Brugge KV]]
|name_BRØ=[[Brøndby IF]]
|name_BSC=[[Hertha BSC]]
|name_BSL=[[FC Basel]]
|name_BTE=[[FC BATE Borisov]]
|name_BUR=[[Bursaspor]]
|name_CEL=[[Celta de Vigo]]
|name_CEL=[[Celtic F.C.]]
|name_CFR=[[CFR Cluj]]
|name_CHL=[[Chelsea F.C.]]
|name_CSM=[[PFC CSKA Moscow]]
|name_CSS=[[PFC CSKA Sofia]]
|name_DB =[[FC Dinamo București]]
|name_DEB=[[Debreceni VSC]]
|name_DEP=[[Deportivo de La Coruña]]
|name_DK =[[FC Dynamo Kyiv]]
|name_DNI=[[FC Dnipro Dnipropetrovsk]]
|name_DOR=[[Borussia Dortmund]]
|name_DTB=[[FC Dinamo Tbilisi]]
|name_DZ =[[GNK Dinamo Zagreb]]
|name_DZ =[[NK Dinamo Zagreb]]
|name_EGA=[[Egaleo FC]]
|name_EIN=[[Eintracht Frankfurt]]
|name_ELF=[[IF Elfsborg]]
|name_ESP=[[RCD Espanyol]]
|name_EVE=[[Everton F.C.]]
|name_FCK=[[F.C. Copenhagen]]
|name_FCN=[[FC Nordsjælland]]
|name_FEN=[[Fenerbahçe S.K. (football)]]
|name_FER=[[Ferencvárosi TC]]
|name_FEY=[[Feyenoord]]
|name_FIO=[[ACF Fiorentina]]
|name_FUL=[[Fulham F.C.]]
|name_GAK=[[Grazer AK]]
|name_GAL=[[Galatasaray S.K. (football team)]]
|name_GAL=[[Galatasaray S.K. (football)]]
|name_GEN=[[Genoa C.F.C.]]
|name_GET=[[Getafe CF]]
|name_GNK=[[K.R.C. Genk]]
|name_GRA=[[Grasshopper Club Zürich]]
|name_HAP=[[Hapoel Tel Aviv F.C.]]
|name_HBK=[[Halmstads BK]]
|name_HEL=[[Helsingborgs IF]]
|name_HER=[[Hertha BSC]]
|name_HOM=[[Heart of Midlothian F.C.]]
|name_HSV=[[Hamburger SV]]
|name_HVN=[[SC Heerenveen]]
|name_INT=[[Inter Milan]]
|name_JUV=[[Juventus F.C.]]
|name_LAR=[[Athlitiki Enosi Larissa F.C.]]
|name_LAZ=[[S.S. Lazio]]
|name_LEN=[[RC Lens]]
|name_LEV=[[Bayer 04 Leverkusen]]
|name_LIB=[[FC Slovan Liberec]]
|name_LIL=[[Lille OSC]]
|name_LIT=[[PFC Litex Lovech]]
|name_LIV=[[A.S. Livorno Calcio]]
|name_LIV=[[Liverpool F.C.]]
|name_LOK=[[FC Lokomotiv Moscow]]
|name_LPO=[[Lech Poznań]]
|name_LS =[[PFC Levski Sofia]]
|name_LUD=[[PFC Ludogorets Razgrad]]
|name_MAL=[[Malmö FF]]
|name_MAL=[[Málaga CF]]
|name_MC =[[Manchester City F.C.]]
|name_MET=[[FC Metalist Kharkiv]]
|name_MH =[[Montpellier HSC]]
|name_MHA=[[Maccabi Haifa F.C.]]
|name_MID=[[Middlesbrough F.C.]]
|name_MLA=[[FK Mladá Boleslav]]
|name_MON=[[AS Monaco FC]]
|name_MPT=[[Maccabi Petah Tikva F.C.]]
|name_MRB=[[NK Maribor]]
|name_MU =[[Manchester United F.C.]]
|name_NAN=[[AS Nancy]]
|name_NAP=[[S.S.C. Napoli]]
|name_NCL=[[C.D. Nacional]]
|name_NEC=[[N.E.C. (football club)]]
|name_NEW=[[Newcastle United F.C.]]
|name_NÜR=[[1. FC Nürnberg]]
|name_ODE=[[Odense Boldklub]]
|name_OG =[[FC Oțelul Galați]]
|name_OL =[[Olympique Lyonnais]]
|name_OLY=[[Olympiacos F.C.]]
|name_OM =[[Olympique de Marseille]]
|name_OSA=[[CA Osasuna]]
|name_PAL=[[U.S. Città di Palermo]]
|name_PAN=[[Panathinaikos F.C.]]
|name_PAN=[[Panionios F.C.]]
|name_PAN=[[Panionios NFC]]
|name_PAOK=[[PAOK FC]]
|name_PAR=[[Parma F.C.]]
|name_PAR=[[S.S.D. Parma Calcio 1913]]
|name_PLZ=[[FC Viktoria Plzeň]]
|name_POR=[[FC Porto]]
|name_POR=[[Portsmouth F.C.]]
|name_PRA=[[AC Sparta Prague]]
|name_PRA=[[Sparta Prague]]
|name_PSG=[[Paris Saint-Germain F.C.]]
|name_PSV=[[PSV Eindhoven]]
|name_PTZ=[[FK Partizan]]
|name_RAN=[[Rangers F.C.]]
|name_RAP=[[FC Rapid Bucureşti]]
|name_RAP=[[FC Rapid București]]
|name_RAP=[[SK Rapid Wien]]
|name_RCL=[[RC Lens]]
|name_REN=[[Stade Rennais F.C.]]
|name_RM =[[Real Madrid C.F.]]
|name_ROM=[[A.S. Roma]]
|name_ROS=[[Rosenborg BK]]
|name_RSA=[[Racing de Santander]]
|name_RSB=[[Red Star Belgrade]]
|name_RSO=[[Real Sociedad]]
|name_RUB=[[FC Rubin Kazan]]
|name_SAM=[[U.C. Sampdoria]]
|name_SBG=[[FC Red Bull Salzburg]]
|name_SCH=[[FC Schalke 04]]
|name_SCP=[[Sporting Clube de Portugal]]
|name_SEV=[[Sevilla FC]]
|name_SHF=[[FC Sheriff Tiraspol]]
|name_SHK=[[FC Shakhtar Donetsk]]
|name_SLA=[[SK Slavia Prague]]
|name_SLV=[[Slavia Prague]]
|name_SOC=[[FC Sochaux-Montbéliard]]
|name_SPM=[[FC Spartak Moscow]]
|name_STD=[[Standard Liège]]
|name_STE=[[AS Saint-Étienne]]
|name_STE=[[FC Steaua București]]
|name_STM=[[SK Sturm Graz]]
|name_STR=[[RC Strasbourg]]
|name_STU=[[VfB Stuttgart]]
|name_TIM=[[FC Politehnica Timișoara]]
|name_TOT=[[Tottenham Hotspur F.C.]]
|name_TOU=[[Toulouse FC]]
|name_TRA=[[Trabzonspor]]
|name_TRO=[[Tromsø IL]]
|name_TWE=[[FC Twente]]
|name_UDI=[[Udinese Calcio]]
|name_URZ=[[FC Unirea Urziceni]]
|name_UTR=[[F.C. Utrecht]]
|name_VAL=[[Valencia CF]]
|name_VEN=[[FK Ventspils]]
|name_VIK=[[Viking FK]]
|name_VIL=[[Villarreal CF]]
|name_VIT=[[Vitória S.C.]]
|name_WIS=[[Wisła Kraków]]
|name_WOL=[[VfL Wolfsburg]]
|name_ZAR=[[Real Zaragoza]]
|name_ZEN=[[FC Zenit Saint Petersburg]]
|name_ZIL=[[MŠK Žilina]]
|name_ZWA=[[S.V. Zulte Waregem]]
|name_ZÜR=[[FC Zürich]]
|name_AHL=[[Al Ahly SC]]
|name_AHL=[[Al-Ahly S.C.]]
|name_ALM=[[Al-Merreikh]]
|name_ASA=[[Asante Kotoko]]
|name_ASEC=[[ASEC Mimosas]]
|name_COT=[[Coton Sport FC de Garoua]]
|name_CSS=[[CS Sfaxien]]
|name_DYN=[[Dynamos F.C.]]
|name_DYN=[[Dynamos Harare]]
|name_ENY=[[Enyimba International F.C.]]
|name_ESP=[[Espérance ST]]
|name_ESP=[[Espérance de Tunis]]
|name_ESS=[[ES Sétif]]
|name_ESS=[[Étoile du Sahel]]
|name_EST=[[Espérance Sportive de Tunis]]
|name_ETO=[[Etoile sportive du Sahel]]
|name_FAR=[[FAR Rabat]]
|name_HEA=[[Heartland F.C.]]
|name_HEA=[[Heartland FC]]
|name_HIL=[[Al-Hilal (Omdurman)]]
|name_HIL=[[Al-Hilal Club (Omdurman)]]
|name_HIL=[[Al-Hilal Omdurman]]
|name_ISM=[[Ismaily]]
|name_ITT=[[Al-Ittihad Club (Tripoli)]]
|name_JSK=[[JS Kabylie]]
|name_KAN=[[Kano Pillars F.C.]]
|name_MCA=[[MC Alger]]
|name_MON=[[Monomotapa United F.C.]]
|name_OAK=[[Accra Hearts of Oak Sporting Club]]
|name_ORL=[[Orlando Pirates Football Club]]
|name_RCA=[[Raja CA Casablanca]]
|name_TPM=[[TP Mazembe]]
|name_WAC=[[Wydad Casablanca]]
|name_ZAM=[[Al-Zamalek]]
|name_ZES=[[ZESCO United F.C.]]
|name_AFG=[[Afghanistan]]
|name_ALB=[[Albania]]
|name_ALG=[[Algeria]]
|name_AND=[[Andorra]]
|name_ANG=[[Angola]]
|name_ANT=[[Antigua and Barbuda]]
|name_ARG=[[Argentina]]
|name_ARM=[[Armenia]]
|name_ARU=[[Aruba]]
|name_ASA=[[American Samoa]]
|name_AUS=[[Australia]]
|name_AUT=[[Austria]]
|name_AZE=[[Azerbaijan]]
|name_BAH=[[Bahamas]]
|name_BAN=[[Bangladesh]]
|name_BAR=[[Barbados]]
|name_BDI=[[Burundi]]
|name_BEL=[[Belgium]]
|name_BEN=[[Benin]]
|name_BER=[[Bermuda]]
|name_BHU=[[Bhutan]]
|name_BIH=[[Bosnia and Herzegovina]]
|name_BIZ=[[Belize]]
|name_BLR=[[Belarus]]
|name_BOL=[[Bolivia]]
|name_BOT=[[Botswana]]
|name_BRA=[[Brazil]]
|name_BRN=[[Bahrain]]
|name_BRU=[[Brunei]]
|name_BUL=[[Bulgaria]]
|name_BUR=[[Burkina Faso]]
|name_CAF=[[Central African Republic]]
|name_CAM=[[Cambodia]]
|name_CAN=[[Canada]]
|name_CAY=[[Cayman Islands]]
|name_CGO=[[Republic of the Congo]]
|name_CHA=[[Chad]]
|name_CHI=[[Chile]]
|name_CHN=[[China]]
|name_CIV=[[Ivory Coast]]
|name_CMR=[[Cameroon]]
|name_COD=[[Democratic Republic of the Congo]]
|name_COK=[[Cook Islands]]
|name_COL=[[Colombia]]
|name_COM=[[Comoros]]
|name_CPV=[[Cape Verde]]
|name_CRC=[[Costa Rica]]
|name_CRO=[[Croatia]]
|name_CUB=[[Cuba]]
|name_CYP=[[Cyprus]]
|name_CZE=[[Czech Republic]]
|name_DEN=[[Denmark]]
|name_DJI=[[Djibouti]]
|name_DMA=[[Dominica]]
|name_DOM=[[Dominican Republic]]
|name_ECU=[[Ecuador]]
|name_EGY=[[Egypt]]
|name_ERI=[[Eritrea]]
|name_ESA=[[El Salvador]]
|name_ESP=[[Spain]]
|name_EST=[[Estonia]]
|name_ETH=[[Ethiopia]]
|name_FIJ=[[Fiji]]
|name_FIN=[[Finland]]
|name_FRA=[[France]]
|name_FSM=[[Federated States of Micronesia]]
|name_GAB=[[Gabon]]
|name_GAM=[[The Gambia]]
|name_GBR=[[Great Britain]]
|name_GBS=[[Guinea-Bissau]]
|name_GEO=[[Georgia]]
|name_GEQ=[[Equatorial Guinea]]
|name_GER=[[Germany]]
|name_GHA=[[Ghana]]
|name_GRE=[[Greece]]
|name_GRN=[[Grenada]]
|name_GUA=[[Guatemala]]
|name_GUI=[[Guinea]]
|name_GUM=[[Guam]]
|name_GUY=[[Guyana]]
|name_HAI=[[Haiti]]
|name_HKG=[[Hong Kong]]
|name_HON=[[Honduras]]
|name_HUN=[[Hungary]]
|name_INA=[[Indonesia]]
|name_IND=[[India]]
|name_IRI=[[Iran]]
|name_IRL=[[Ireland]]
|name_IRQ=[[Iraq]]
|name_ISL=[[Iceland]]
|name_ISR=[[Israel]]
|name_ISV=[[Virgin Islands]]
|name_ITA=[[Italy]]
|name_IVB=[[British Virgin Islands]]
|name_JAM=[[Jamaica]]
|name_JOR=[[Jordan]]
|name_JPN=[[Japan]]
|name_KAZ=[[Kazakhstan]]
|name_KEN=[[Kenya]]
|name_KGZ=[[Kyrgyzstan]]
|name_KIR=[[Kiribati]]
|name_KOR=[[South Korea]]
|name_KOS=[[Kosovo]]
|name_KSA=[[Saudi Arabia]]
|name_KUW=[[Kuwait]]
|name_LAO=[[Laos]]
|name_LAT=[[Latvia]]
|name_LBA=[[Libya]]
|name_LIB=[[Lebanon]]
|name_LBN=[[Lebanon]]
|name_LBR=[[Liberia]]
|name_LCA=[[Saint Lucia]]
|name_LES=[[Lesotho]]
|name_LIE=[[Liechtenstein]]
|name_LTU=[[Lithuania]]
|name_LUX=[[Luxembourg]]
|name_MAD=[[Madagascar]]
|name_MAR=[[Morocco]]
|name_MAS=[[Malaysia]]
|name_MAW=[[Malawi]]
|name_MDA=[[Moldova]]
|name_MDV=[[Maldives]]
|name_MEX=[[Mexico]]
|name_MGL=[[Mongolia]]
|name_MHL=[[Marshall Islands]]
|name_MKD=[[North Macedonia]]
|name_MLI=[[Mali]]
|name_MLT=[[Malta]]
|name_MNE=[[Montenegro]]
|name_MON=[[Monaco]]
|name_MOZ=[[Mozambique]]
|name_MRI=[[Mauritius]]
|name_MTN=[[Mauritania]]
|name_MYA=[[Myanmar]]
|name_NAM=[[Namibia]]
|name_NCA=[[Nicaragua]]
|name_NED=[[Netherlands]]
|name_NEP=[[Nepal]]
|name_NGR=[[Nigeria]]
|name_NIG=[[Niger]]
|name_NOR=[[Norway]]
|name_NRU=[[Nauru]]
|name_NZL=[[New Zealand]]
|name_OMA=[[Oman]]
|name_PAK=[[Pakistan]]
|name_PAN=[[Panama]]
|name_PAR=[[Paraguay]]
|name_PER=[[Peru]]
|name_PHI=[[Philippines]]
|name_PLE=[[Palestine]]
|name_PLW=[[Palau]]
|name_PNG=[[Papua New Guinea]]
|name_POL=[[Poland]]
|name_POR=[[Portugal]]
|name_PRK=[[North Korea]]
|name_PUR=[[Puerto Rico]]
|name_QAT=[[Qatar]]
|name_ROU=[[Romania]]
|name_RSA=[[South Africa]]
|name_RUS=[[Russia]]
|name_RWA=[[Rwanda]]
|name_SAM=[[Samoa]]
|name_SEN=[[Senegal]]
|name_SEY=[[Seychelles]]
|name_SGP=[[Singapore]]
|name_SKN=[[Saint Kitts and Nevis]]
|name_SLE=[[Sierra Leone]]
|name_SLO=[[Slovenia]]
|name_SMR=[[San Marino]]
|name_SOL=[[Solomon Islands]]
|name_SOM=[[Somalia]]
|name_SRB=[[Serbia]]
|name_SRI=[[Sri Lanka]]
|name_SSD=[[South Sudan]]
|name_STP=[[São Tomé and Príncipe]]
|name_SUD=[[Sudan]]
|name_SUI=[[Switzerland]]
|name_SUR=[[Suriname]]
|name_SVK=[[Slovakia]]
|name_SWE=[[Sweden]]
|name_SWZ=[[Swaziland]]
|name_SYR=[[Syria]]
|name_TAN=[[Tanzania]]
|name_TGA=[[Tonga]]
|name_THA=[[Thailand]]
|name_TJK=[[Tajikistan]]
|name_TKM=[[Turkmenistan]]
|name_TLS=[[East Timor]]
|name_TOG=[[Togo]]
|name_TPE=[[Chinese Taipei]]
|name_TRI=[[Trinidad and Tobago]]
|name_TTO=[[Trinidad and Tobago]]
|name_TUN=[[Tunisia]]
|name_TUR=[[Turkey]]
|name_TUV=[[Tuvalu]]
|name_UAE=[[United Arab Emirates]]
|name_UGA=[[Uganda]]
|name_UKR=[[Ukraine]]
|name_URU=[[Uruguay]]
|name_USA=[[United States]]
|name_UZB=[[Uzbekistan]]
|name_VAN=[[Vanuatu]]
|name_VEN=[[Venezuela]]
|name_VIE=[[Vietnam]]
|name_VIN=[[Saint Vincent and the Grenadines]]
|name_YEM=[[Yemen]]
|name_ZAM=[[Zambia]]
|name_ZIM=[[Zimbabwe]]
|name_BEN=[[Bendigo Bombers]]
|name_BEN=[[Bendigo Football Club]]
|name_BOX=[[Box Hill Football Club]]
|name_BOX=[[Box Hill Hawks]]
|name_CAS=[[Casey Scorpions]]
|name_COB=[[Coburg Football Club]]
|name_COB=[[Coburg Tigers]]
|name_COL=[[Collingwood Football Club#Reserves team]]
|name_COL=[[Collingwood Football Club]]
|name_DAN=[[Dandenong Football Club]]
|name_FRA=[[Frankston Dolphins]]
|name_FRA=[[Frankston Football Club]]
|name_GC =[[Gold Coast Football Club]]
|name_GEE=[[Geelong Cats]]
|name_GEE=[[Geelong Football Club (VFL)]]
|name_GEE=[[Geelong Football Club#Reserves team]]
|name_GEE=[[Geelong Football Club]]
|name_NBR=[[North Ballarat Football Club]]
|name_NBR=[[North Ballarat Roosters]]
|name_NBU=[[Northern Blues]]
|name_NBU=[[Northern Bullants]]
|name_OAK=[[Oakleigh Football Club]]
|name_PMB=[[Port Melbourne Borough]]
|name_PMB=[[Port Melbourne Boroughs]]
|name_PMB=[[Port Melbourne Football Club]]
|name_PRA=[[Prahran Football Club]]
|name_PRE=[[Preston Football Club (VFA)]]
|name_SAN=[[Sandringham Football Club]]
|name_SAN=[[Sandringham Zebras]]
|name_SPR=[[Springvale Football Club]]
|name_TAS=[[Tasmanian Devils Football Club]]
|name_TRA=[[Traralgon Football Club]]
|name_WER=[[Werribee Football Club]]
|name_WER=[[Werribee Tigers]]
|name_WIL=[[Williamstown Football Club]]
|name_WIL=[[Williamstown Seagulls]]
|name_BER=[[Berwick Football Club]]
|name_BOX=[[Box Hill Football Club]]
|name_BRU=[[Brunswick Football Club]]
|name_CAM=[[Camberwell Football Club]]
|name_CAU=[[Caulfield Football Club]]
|name_COB=[[Coburg Football Club]]
|name_DAN=[[Dandenong Football Club]]
|name_FRA=[[Frankston Football Club]]
|name_GLW=[[Geelong West Football Club]]
|name_KIL=[[Kilsyth Football Club]]
|name_MOO=[[Moorabbin Football Club]]
|name_MOR=[[Mordialloc Football Club]]
|name_NBU=[[Northern Blues]]
|name_NOR=[[Northcote Football Club]]
|name_OAK=[[Oakleigh Football Club]]
|name_PMB=[[Port Melbourne Football Club]]
|name_PRA=[[Prahran Football Club]]
|name_SAN=[[Sandringham Football Club]]
|name_SPR=[[Springvale Football Club]]
|name_SUN=[[Sunshine Football Club (VFA)]]
|name_WAV=[[Waverley Football Club]]
|name_WER=[[Werribee Football Club]]
|name_WIL=[[Williamstown Football Club]]
|name_YAR=[[Yarraville Football Club]]
|name_DLSU=[[La Salle]]
|name_AdU=[[Adamson]]
|name_AdMU=[[Ateneo]]
`;
var oldtext = myContent.value;
myContent.value = wpFbGenFix(myContent.value);
myContent.value = wpFbUnpre(myContent.value);
myContent.value = wpFbCols(myContent.value);
myContent.value = myContent.value.replace(/(<onlyinclude>)[\t ]*[\r\n]*/g, '$1');
var sections = myContent.value.split(/(\{\{[_\s]*[Ff]b[_\s]+(?:ha|cl|r)2?[_\s]+header|\{\{[_\s]*Vb[_\s]+cl[0-9*[_\s]+header|\{\{[_\s]*Vb[_\s]+res[_\s]+start|\{\{[_\s]*(?:[Ii]ce[_ ]*[Hh]ockey|[Bb]asketball|[Hh]andball|[Ff]ootball|[Rr]ugby)[_ ]*box|\{\{[_\s]*[Ff]b[_\s]+rbr[_\s]+pos[_\s]+header|\{\{[\s]*#invoke:[\s]*[Ss]ports|\{\{PHL sports sked header|[\r\n]\{\|)/g);
// begin convoluted loop
var i=0;
function myLoop() {
if ( sections[i].search(/(\{\{[_\s]*[Ff]b[_\s]+(?:ha|cl|r)2?[_\s]+header|\{\{[_\s]*Vb[_\s]+cl[0-9*[_\s]+header|\{\{[_\s]*Vb[_\s]+res[_\s]+start|\{\{[_\s]*(?:[Ii]ce[_ ]*[Hh]ockey|[Bb]asketball|[Hh]andball|[Ff]ootball|[Rr]ugby)[_ ]*box|\{\{[_\s]*[Ff]b[_\s]+rbr[_\s]+pos[_\s]+header|\{\{[\s]*#invoke:[\s]*[Ss]ports|\{\{PHL sports sked header|[\r\n]\{\|)/g) >= 0 ) {
if ((i+1) < sections.length) {
sections[i] = sections[i] + sections[i+1];
sections[i+1] = '';
}
}
sections[i] = wpFbUntable(sections[i]);
sections[i] = wpVB(sections[i]);
sections[i] = wpRugby(sections[i]);
sections[i] = sections[i].replace(/(\{\{[\s_]*[Ll]ocation[_ ]+map\+[\s_]*\|[^\|\{\}]*\|[\s]*float[\s]*=[\s]*)left([\s]*\|(?:\{\{[^{}]*\}\}|[^{}])*\}\})[\s]*(\{\{[\s_]*[Ll]ocation[_ ]+map\+[\s_]*\|[^\|\{\}]*\|[\s]*float[\s]*=[\s]*right[\s]*\|(?:\{\{[^{}]*\}\}|[^{}])*\}\})[\s]*\{\{[_ ]*(?:[Cc]lear[^{}]*|\-)\}\}/g, '$3\n$1none$2');
sections[i] = sections[i].replace(/(\{\{[\s_]*[Ll]ocation[_ ]+map\+[\s_]*\|[^\|\{\}]*\|[\s]*float[\s]*=[\s]*)left([\s]*\|(?:\{\{[^{}]*\}\}|[^{}])*\}\})[\s]*\{\{[_ ]*(?:[Cc]lear[^{}]*|\-)\}\}/g, '$1none$2');
if ( sections[i].search(/(\{\{[_\s]*[Ff]b[_\s]+(ha|cl2?)[_ ]+header|\{\{[\s]*#invoke:[\s]*[Ss]ports[\s]*table)/g) >= 0 ) {
sections[i] = wpFbCl(sections[i], sections.join('') , teamset);
sections[i] = wpUnpos(sections[i], sections.join(''));
sections[i] = wpUnlabel(sections[i]);
} else if ( sections[i].search(/(\{\{[_\s]*[Ff]b[_ ]+r2?[_\s]+header|\{\{[\s]*#invoke:[\s]*[Ss]ports[\s]*results)/g) >= 0 ) {
sections[i] = wpFbr2(sections[i], sections.join(''));
}
i++;
if(i<sections.length) {
myLoop();
}
}
myLoop();
// end convoluted loop
myContent.value = sections.join('');
myContent.value = myContent.value.replace(/(<onlyinclude>)[\t ]*[\r\n]*/g, '$1');
if (myContent.value.search(/\|[ ]*source[ ]*=[ \r\n]*(?:\||\}\})/) >= 0) {
if(myContent.value.search(/www\.rsssf\.com\/tablese\/engnwcleaghist\.html/) >= 0){
myContent.value = myContent.value.replace(/(\|[ ]*source[ ]*=)[ ]*([\r\n]?(?:\||\}\}))/g, '$1[' + 'http://www.rsssf.com/tablese/engnwcleaghist.html rsssf.com]' + '$2');
}
}
if (myContent.value.search(/\|[ ]*source[ ]*=[ \r\n]*(?:\||\}\})/) >= 0) {
if(myContent.value.search(/www\.rsssf\.com\/tablesf\/finhist\.html/) >= 0){
myContent.value = myContent.value.replace(/(\|[ ]*source[ ]*=)[ ]*([\r\n]?(?:\||\}\}))/g, '$1[' + 'http://www.rsssf.com/tablesf/finhist.html rsssf.com]' + '$2');
}
}
if (myContent.value.search(/\|[ ]*source[ ]*=[ \r\n]*(?:\||\}\})/) >= 0) {
if(myContent.value.search(/www\.rsssf\.com\/tablesp\/polhist\.html/) >= 0){
myContent.value = myContent.value.replace(/(\|[ ]*source[ ]*=)[ ]*([\r\n]?(?:\||\}\}))/g, '$1[' + 'http://www.rsssf.com/tablesp/polhist.html rsssf.com]' + '$2');
}
}
myContent.value = myContent.value.replace(/(\}\}[\t ]*[\r\n])[\t ]*[\r\n]*[\t ]*[\r\n]*<sup>1 (The points[^<>]*)<\/sup>[\t ]*[\r\n]*/g, '|class_rules=$2\n$1');
if (myContent.value.search(/<!--[\s]*FB/gi) >=0) {
alert('Incomplete reverse table conversion!');
} else if (myContent.value.search(/\{\{[_\s]*[Ff]b[_\s]+cl/gi) >=0) {
alert('Incomplete sports table conversion!');
} else if (myContent.value.search(/\{\{[_\s]*[Ff]b[_\s]+r[^se]/gi) >=0) {
alert('Incomplete sports result conversion!');
}
//myContent.value = myContent.value.replace(/(\{\{subst:#invoke[^{}\t\r\n]*)[\t\r\n]/g, '$1 ');
//myContent.value = myContent.value.replace(/(\{\{subst:#invoke[^{}]*)[\t ][\t ]+/g, '$1 ');
if (myContent.value.search(/[Ss][Uu][Bb][Ss][Tt]:/gi) >= 0) {
myContent.value = myContent.value.replace(/(<)(!--)/g, '$1$2');
myContent.value = myContent.value.replace(/(<)[\s]*(ref|nowiki|includeonly|onlyinclude|noinclude|pre)/gi, '$1$2');
}
if(myContent.value != oldtext) {
myContent.value = myContent.value.replace(/(\{\{[_ ]*[Ff]b[_ ]+a[^{}]*\|[ ]*n)(t[ ]*=)/g, '$1<!-- FB MARK -->$2');
if (myContent.value.search(/\|[\t ]*nt[\t ]*=/g) >=0 ) {
alert('Found |nt=, could be unprocessed notes?');
}
myContent.value = myContent.value.replace(/<!-- FB MARK -->/g, '');
var editsummary = document.getElementsByName('wpSummary')[0];
document.forms.editform.wpMinoredit.checked = true;
editsummary.value = mysummary;
document.forms.editform.wpDiff.click();
}
}
// -------------------------------------------------------------------------------- //
});
// </nowiki>