﻿//XRegExp 1.1.0 <xregexp.com> MIT License
if (!window.XRegExp) { var XRegExp; (function() { XRegExp = function(Q, K) { if (XRegExp.isRegExp(Q)) { if (K !== undefined) { throw TypeError("can't supply flags when constructing one RegExp from another") } return Q.addFlags("") } if (G) { throw Error("can't call the XRegExp constructor within token definition functions") } var K = K || "", J = [], R = 0, O = XRegExp.OUTSIDE_CLASS, L = { hasNamedCapture: false, captureNames: [], hasFlag: function(T) { if (T.length > 1) { throw SyntaxError("flag can't be more than one character") } return K.indexOf(T) > -1 } }, M, P, N, S; while (R < Q.length) { M = I(Q, R, O, L); if (M) { J.push(M.output); R += Math.max(M.matchLength, 1) } else { N = Q.charAt(R); if (P = H.exec.call(E[O], Q.slice(R))) { J.push(P[0]); R += P[0].length } else { if (N === "[") { O = XRegExp.INSIDE_CLASS } else { if (N === "]") { O = XRegExp.OUTSIDE_CLASS } } J.push(N); R++ } } } S = RegExp(J.join(""), H.replace.call(K, /[^gimy]+/g, "")); S._xregexp = { source: Q, captureNames: L.hasNamedCapture ? L.captureNames : null }; return S }; var B = /\$(?:(\d\d?|[$&`'])|{([$\w]+)})/g, A = /()??/.exec("")[1] === undefined, C = function() { var J = /^/g; J.test(""); return !J.lastIndex } (), D = function() { var J = /x/g; "x".replace(J, ""); return !J.lastIndex } (), H = { exec: RegExp.prototype.exec, match: String.prototype.match, replace: String.prototype.replace, split: String.prototype.split, test: RegExp.prototype.test }, I = function(Q, L, P, O) { var N = F.length, K, M, J; G = true; while (N--) { M = F[N]; if ((P & M.scope) && (!M.trigger || M.trigger.call(O))) { M.pattern.lastIndex = L; J = M.pattern.exec(Q); if (J && J.index === L) { K = { output: M.handler.call(O, J, P), matchLength: J[0].length }; break } } } G = false; return K }, G = false, E = {}, F = []; XRegExp.INSIDE_CLASS = 1; XRegExp.OUTSIDE_CLASS = 2; E[XRegExp.INSIDE_CLASS] = /^(?:\\(?:[0-3][0-7]{0,2}|[4-7][0-7]?|x[\dA-Fa-f]{2}|u[\dA-Fa-f]{4}|c[A-Za-z]|[\s\S]))/; E[XRegExp.OUTSIDE_CLASS] = /^(?:\\(?:0(?:[0-3][0-7]{0,2}|[4-7][0-7]?)?|[1-9]\d*|x[\dA-Fa-f]{2}|u[\dA-Fa-f]{4}|c[A-Za-z]|[\s\S])|\(\?[:=!]|[?*+]\?|{\d+(?:,\d*)?}\??)/; XRegExp.addToken = function(M, L, K, J) { F.push({ pattern: XRegExp(M).addFlags("g"), handler: L, scope: K || XRegExp.OUTSIDE_CLASS, trigger: J || null }) }; RegExp.prototype.exec = function(N) { var L = H.exec.apply(this, arguments), K, J; if (L) { if (!A && L.length > 1 && XRegExp._indexOf(L, "") > -1) { J = RegExp("^" + this.source + "$(?!\\s)", XRegExp._getNativeFlags(this)); H.replace.call(L[0], J, function() { for (var O = 1; O < arguments.length - 2; O++) { if (arguments[O] === undefined) { L[O] = undefined } } }) } if (this._xregexp && this._xregexp.captureNames) { for (var M = 1; M < L.length; M++) { K = this._xregexp.captureNames[M - 1]; if (K) { L[K] = L[M] } } } if (!C && this.global && this.lastIndex > (L.index + L[0].length)) { this.lastIndex-- } } return L }; if (!C) { RegExp.prototype.test = function(K) { var J = H.exec.call(this, K); if (J && this.global && this.lastIndex > (J.index + J[0].length)) { this.lastIndex-- } return !!J } } String.prototype.match = function(K) { if (!XRegExp.isRegExp(K)) { K = RegExp(K) } if (K.global) { var J = H.match.apply(this, arguments); K.lastIndex = 0; return J } return K.exec(this) }; String.prototype.replace = function(L, M) { var N = XRegExp.isRegExp(L), K, J, O; if (N && typeof M.valueOf() === "string" && M.indexOf("${") === -1 && D) { return H.replace.apply(this, arguments) } if (!N) { L = L + "" } else { if (L._xregexp) { K = L._xregexp.captureNames } } if (typeof M === "function") { J = H.replace.call(this, L, function() { if (K) { arguments[0] = new String(arguments[0]); for (var P = 0; P < K.length; P++) { if (K[P]) { arguments[0][K[P]] = arguments[P + 1] } } } if (N && L.global) { L.lastIndex = arguments[arguments.length - 2] + arguments[0].length } return M.apply(window, arguments) }) } else { O = this + ""; J = H.replace.call(O, L, function() { var P = arguments; return H.replace.call(M, B, function(R, Q, U) { if (Q) { switch (Q) { case "$": return "$"; case "&": return P[0]; case "`": return P[P.length - 1].slice(0, P[P.length - 2]); case "'": return P[P.length - 1].slice(P[P.length - 2] + P[0].length); default: var S = ""; Q = +Q; if (!Q) { return R } while (Q > P.length - 3) { S = String.prototype.slice.call(Q, -1) + S; Q = Math.floor(Q / 10) } return (Q ? P[Q] : "$") + S } } else { var T = +U; if (T <= P.length - 3) { return P[T] } T = K ? XRegExp._indexOf(K, U) : -1; return T > -1 ? P[T + 1] : R } }) }) } if (N && L.global) { L.lastIndex = 0 } return J }; String.prototype.split = function(N, J) { if (!XRegExp.isRegExp(N)) { return H.split.apply(this, arguments) } var P = this + "", L = [], O = 0, M, K; if (J === undefined || +J < 0) { J = Infinity } else { J = Math.floor(+J); if (!J) { return [] } } N = N.addFlags("g"); while (M = N.exec(P)) { if (N.lastIndex > O) { L.push(P.slice(O, M.index)); if (M.length > 1 && M.index < P.length) { Array.prototype.push.apply(L, M.slice(1)) } K = M[0].length; O = N.lastIndex; if (L.length >= J) { break } } if (!M[0].length) { N.lastIndex++ } } if (O === P.length) { if (!H.test.call(N, "") || K) { L.push("") } } else { L.push(P.slice(O)) } return L.length > J ? L.slice(0, J) : L } })(); RegExp.prototype.addFlags = function(B) { var C = XRegExp(this.source, (B || "") + XRegExp._getNativeFlags(this)), A = this._xregexp; if (A) { C._xregexp = { source: A.source, captureNames: A.captureNames ? A.captureNames.slice(0) : null} } return C }; RegExp.prototype.apply = function(B, A) { return this.exec(A[0]) }; RegExp.prototype.call = function(A, B) { return this.exec(B) }; RegExp.prototype.execAll = function(D) { var C = this.addFlags("g"), A = [], B; while (B = C.exec(D)) { A.push(B); if (!B[0].length) { C.lastIndex++ } } if (this.global) { this.lastIndex = 0 } return A }; RegExp.prototype.forEachExec = function(E, F, C) { var D = this.addFlags("g"), B = -1, A; while (A = D.exec(E)) { F.call(C, A, ++B, E, D); if (!A[0].length) { D.lastIndex++ } } if (this.global) { this.lastIndex = 0 } }; RegExp.prototype.validate = function(B) { var A = RegExp("^(?:" + this.source + ")$(?!\\s)", XRegExp._getNativeFlags(this)); if (this.global) { this.lastIndex = 0 } return B.search(A) === 0 }; XRegExp.cache = function(C, A) { var B = "/" + C + "/" + (A || ""); return XRegExp.cache[B] || (XRegExp.cache[B] = XRegExp(C, A)) }; XRegExp.escape = function(A) { return A.replace(/[-[\]{}()*+?.\\^$|,#\s]/g, "\\$&") }; XRegExp.freezeTokens = function() { XRegExp.addToken = null }; XRegExp.isRegExp = function(A) { return Object.prototype.toString.call(A) === "[object RegExp]" }; XRegExp.matchWithinChain = function(E, A, B) { var C; function D(G, L) { var J = A[L].addFlags("g"), F = [], K, I, H; for (I = 0; I < G.length; I++) { if (B) { K = J.execAll(G[I][0]); for (H = 0; H < K.length; H++) { K[H].index += G[I].index } } else { K = G[I].match(J) } if (K) { F.push(K) } } F = Array.prototype.concat.apply([], F); if (A[L].global) { A[L].lastIndex = 0 } return L === A.length - 1 ? F : D(F, L + 1) } if (B) { C = { "0": E, index: 0} } return D([B ? C : E], 0) }; XRegExp._getNativeFlags = function(A) { return (A.global ? "g" : "") + (A.ignoreCase ? "i" : "") + (A.multiline ? "m" : "") + (A.extended ? "x" : "") + (A.sticky ? "y" : "") }; XRegExp._indexOf = function(D, B, C) { for (var A = C || 0; A < D.length; A++) { if (D[A] === B) { return A } } return -1 }; (function() { var A = /^(?:[?*+]|{\d+(?:,\d*)?})\??/; XRegExp.addToken(/\(\?#[^)]*\)/, function(B) { return A.test(B.input.slice(B.index + B[0].length)) ? "" : "(?:)" }); XRegExp.addToken(/\((?!\?)/, function() { this.captureNames.push(null); return "(" }); XRegExp.addToken(/\(\?<([$\w]+)>/, function(B) { this.captureNames.push(B[1]); this.hasNamedCapture = true; return "(" }); XRegExp.addToken(/\\k<([\w$]+)>/, function(C) { var B = XRegExp._indexOf(this.captureNames, C[1]); return B > -1 ? "\\" + (B + 1) + (isNaN(C.input.charAt(C.index + C[0].length)) ? "" : "(?:)") : C[0] }); XRegExp.addToken(/\[\^?]/, function(B) { return B[0] === "[]" ? "\\b\\B" : "[\\s\\S]" }); XRegExp.addToken(/(?:\s+|#.*)+/, function(B) { return A.test(B.input.slice(B.index + B[0].length)) ? "" : "(?:)" }, XRegExp.OUTSIDE_CLASS, function() { return this.hasFlag("x") }); XRegExp.addToken(/\./, function() { return "[\\s\\S]" }, XRegExp.OUTSIDE_CLASS, function() { return this.hasFlag("s") }) })(); XRegExp.version = "1.1.0" };
