//XRegExp 0.6.1;<stevenlevithan.com>;MIT License
if(!window.XRegExp){(function(){var E={exec:RegExp.prototype.exec,match:String.prototype.match,replace:String.prototype.replace,split:String.prototype.split},D={part:/(?:[^\\([#\s.]+|\\(?!k<[\w$]+>|[pP]{[^}]+})[\S\s]?|\((?=\?(?!#|<[\w$]+>)))+|(\()(?:\?(?:(#)[^)]*\)|<([$\w]+)>))?|\\(?:k<([\w$]+)>|[pP]{([^}]+)})|(\[\^?)|([\S\s])/g,replaceVar:/(?:[^$]+|\$(?![1-9$&`']|{[$\w]+}))+|\$(?:([1-9]\d*|[$&`'])|{([$\w]+)})/g,extended:/^(?:\s+|#.*)+/,quantifier:/^(?:[?*+]|{\d+(?:,\d*)?})/,classLeft:/&&\[\^?/g,classRight:/]/g},B=function(I,G,H){for(var F=H||0;F<I.length;F++){if(I[F]===G){return F}}return -1},C=/()??/.exec("")[1]!==undefined,A={};XRegExp=function(O,I){if(O instanceof RegExp){if(I!==undefined){throw TypeError("can't supply flags when constructing one RegExp from another")}return O.addFlags()}var I=I||"",F=I.indexOf("s")>-1,K=I.indexOf("x")>-1,P=false,R=[],H=[],G=D.part,L,J,N,M,Q;G.lastIndex=0;while(L=E.exec.call(G,O)){if(L[2]){if(!D.quantifier.test(O.slice(G.lastIndex))){H.push("(?:)")}}else{if(L[1]){R.push(L[3]||null);if(L[3]){P=true}H.push("(")}else{if(L[4]){M=B(R,L[4]);H.push(M>-1?"\\"+(M+1)+(isNaN(O.charAt(G.lastIndex))?"":"(?:)"):L[0])}else{if(L[5]){H.push(A.unicode?A.unicode.get(L[5],L[0].charAt(1)==="P"):L[0])}else{if(L[6]){if(O.charAt(G.lastIndex)==="]"){H.push(L[6]==="["?"(?!)":"[\\S\\s]");G.lastIndex++}else{J=XRegExp.matchRecursive("&&"+O.slice(L.index),D.classLeft,D.classRight,"",{escapeChar:"\\"})[0];H.push(L[6]+J+"]");G.lastIndex+=J.length+1}}else{if(L[7]){if(F&&L[7]==="."){H.push("[\\S\\s]")}else{if(K&&D.extended.test(L[7])){N=E.exec.call(D.extended,O.slice(G.lastIndex-1))[0].length;if(!D.quantifier.test(O.slice(G.lastIndex-1+N))){H.push("(?:)")}G.lastIndex+=N-1}else{H.push(L[7])}}}else{H.push(L[0])}}}}}}}Q=RegExp(H.join(""),E.replace.call(I,/[sx]+/g,""));Q._x={source:O,captureNames:P?R:null};return Q};XRegExp.addPlugin=function(F,G){A[F]=G};RegExp.prototype.exec=function(J){var H=E.exec.call(this,J),G,I,F;if(H){if(C&&H.length>1){F=new RegExp("^"+this.source+"$(?!\\s)",this.getNativeFlags());E.replace.call(H[0],F,function(){for(I=1;I<arguments.length-2;I++){if(arguments[I]===undefined){H[I]=undefined}}})}if(this._x&&this._x.captureNames){for(I=1;I<H.length;I++){G=this._x.captureNames[I-1];if(G){H[G]=H[I]}}}if(this.global&&this.lastIndex>(H.index+H[0].length)){this.lastIndex--}}return H};String.prototype.match=function(F){if(!(F instanceof RegExp)){F=new XRegExp(F)}if(F.global){return E.match.call(this,F)}return F.exec(this)};String.prototype.replace=function(G,H){var F=(G._x||{}).captureNames;if(!(G instanceof RegExp&&F)){return E.replace.apply(this,arguments)}if(typeof H==="function"){return E.replace.call(this,G,function(){arguments[0]=new String(arguments[0]);for(var I=0;I<F.length;I++){if(F[I]){arguments[0][F[I]]=arguments[I+1]}}return H.apply(window,arguments)})}else{return E.replace.call(this,G,function(){var I=arguments;return E.replace.call(H,D.replaceVar,function(K,J,N){if(J){switch(J){case"$":return"$";case"&":return I[0];case"`":return I[I.length-1].slice(0,I[I.length-2]);case"'":return I[I.length-1].slice(I[I.length-2]+I[0].length);default:var L="";J=+J;while(J>F.length){L=E.split.call(J,"").pop()+L;J=Math.floor(J/10)}return(J?I[J]:"$")+L}}else{if(N){var M=B(F,N);return M>-1?I[M+1]:K}else{return K}}})})}};String.prototype.split=function(L,G){if(!(L instanceof RegExp)){return E.split.apply(this,arguments)}var I=[],F=L.lastIndex,M=0,K=0,J,H;if(G===undefined||+G<0){G=false}else{G=Math.floor(+G);if(!G){return[]}}if(L.global){L.lastIndex=0}else{L=L.addFlags("g")}while((!G||K++<=G)&&(J=L.exec(this))){if(L.lastIndex>M){I=I.concat(this.slice(M,J.index));if(1<J.length&&J.index<this.length){I=I.concat(J.slice(1))}H=J[0].length;M=L.lastIndex}if(!J[0].length){L.lastIndex++}}I=M===this.length?(L.test("")&&!H?I:I.concat("")):(G?I:I.concat(this.slice(M)));L.lastIndex=F;return I}})()}RegExp.prototype.getNativeFlags=function(){return(this.global?"g":"")+(this.ignoreCase?"i":"")+(this.multiline?"m":"")+(this.extended?"x":"")+(this.sticky?"y":"")};RegExp.prototype.addFlags=function(A){var B=new XRegExp(this.source,(A||"")+this.getNativeFlags());if(this._x){B._x={source:this._x.source,captureNames:this._x.captureNames?this._x.captureNames.slice(0):null}}return B};RegExp.prototype.call=function(A,B){return this.exec(B)};RegExp.prototype.apply=function(B,A){return this.exec(A[0])};XRegExp.cache=function(C,A){var B="/"+C+"/"+(A||"");return XRegExp.cache[B]||(XRegExp.cache[B]=new XRegExp(C,A))};XRegExp.escape=function(A){return A.replace(/[-[\]{}()*+?.\\^$|,#\s]/g,"\\$&")};XRegExp.matchRecursive=function(P,D,S,F,B){var B=B||{},V=B.escapeChar,K=B.valueNames,F=F||"",Q=F.indexOf("g")>-1,C=F.indexOf("i")>-1,H=F.indexOf("m")>-1,U=F.indexOf("y")>-1,F=F.replace(/y/g,""),D=D instanceof RegExp?(D.global?D:D.addFlags("g")):new XRegExp(D,"g"+F),S=S instanceof RegExp?(S.global?S:S.addFlags("g")):new XRegExp(S,"g"+F),I=[],A=0,J=0,N=0,L=0,M,E,O,R,G,T;if(V){if(V.length>1){throw SyntaxError("can't supply more than one escape character")}if(H){throw TypeError("can't supply escape character when using the multiline flag")}G=XRegExp.escape(V);T=new RegExp("^(?:"+G+"[\\S\\s]|(?:(?!"+D.source+"|"+S.source+")[^"+G+"])+)+",C?"i":"")}while(true){D.lastIndex=S.lastIndex=N+(V?(T.exec(P.slice(N))||[""])[0].length:0);O=D.exec(P);R=S.exec(P);if(O&&R){if(O.index<=R.index){R=null}else{O=null}}if(O||R){J=(O||R).index;N=(O?D:S).lastIndex}else{if(!A){break}}if(U&&!A&&J>L){break}if(O){if(!A++){M=J;E=N}}else{if(R&&A){if(!--A){if(K){if(K[0]&&M>L){I.push([K[0],P.slice(L,M),L,M])}if(K[1]){I.push([K[1],P.slice(M,E),M,E])}if(K[2]){I.push([K[2],P.slice(E,J),E,J])}if(K[3]){I.push([K[3],P.slice(J,N),J,N])}}else{I.push(P.slice(E,J))}L=N;if(!Q){break}}}else{D.lastIndex=S.lastIndex=0;throw Error("subject data contains unbalanced delimiters")}}if(J===N){N++}}if(Q&&!U&&K&&K[0]&&P.length>L){I.push([K[0],P.slice(L),L,P.length])}D.lastIndex=S.lastIndex=0;return I};

