diff --git a/README.md b/README.md index 5f7d31b..8e64d2b 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ A generic, simple & intuitive **Regular Expression Analyzer & Composer** Java, C/C++, ActionScript (TODO) -**Regex v.1.0.0** +**Regex v.1.0.1** **see also:** diff --git a/src/js/Regex.js b/src/js/Regex.js index 9e59ff9..1a6a317 100644 --- a/src/js/Regex.js +++ b/src/js/Regex.js @@ -1,7 +1,7 @@ /** * * Regex -* @version: 1.0.0 +* @version: 1.0.1 * * A simple & generic Regular Expression Analyzer & Composer for PHP, Python, Node/XPCOM/JS, Java, C/C++, ActionScript * https://github.com/foo123/RegexAnalyzer @@ -23,7 +23,7 @@ else if ( !(name in root) ) /* Browser/WebWorker/.. */ /* module name */ "Regex", /* module factory */ function ModuleFactory__Regex( undef ){ "use strict"; -var __version__ = "1.0.0", +var __version__ = "1.0.1", PROTO = 'prototype', OP = Object[PROTO], AP = Array[PROTO], Keys = Object.keys, to_string = OP.toString, HAS = OP.hasOwnProperty, @@ -861,7 +861,7 @@ var rnd = function( a, b ){ return Math.round((b-a)*Math.random()+a); }, } else { - ret.src += !node.flags.MatchStart && !node.flags.MatchEnd ? (ESC+node.val) : (''+node.val); + ret.src += node.flags.MatchAnyChar || node.flags.MatchStart || node.flags.MatchEnd ? (''+node.val) : (ESC+node.val); } } else if ( T_STRING === type ) @@ -918,6 +918,10 @@ var rnd = function( a, b ){ return Math.round((b-a)*Math.random()+a); }, { ret[inNegativeCharGroup?"positive":"negative"][ '\\s' ] = 1; } + else if ('B' === part) + { + ret[inNegativeCharGroup?"positive":"negative"][ '\\b' ] = 1; + } else { ret[peek][ESC + part] = 1; @@ -1732,6 +1736,12 @@ Analyzer[PROTO] = { cases = concat(cases, ['_'].concat(character_range('0', '9')).concat(character_range('a', 'z')).concat(character_range('A', 'Z'))); } + else if ('\\b' === c) + { + delete p[c]; + cases[ specialChars['b'] ] = 1; + } + else if ('\\.' === c) { delete p[c]; @@ -1999,14 +2009,22 @@ Composer[PROTO] = { return this.alternate(); }, - group: function( opts ) { + group: function( opts, v ) { var self = this, type = T_GROUP, fl = ''; - opts = opts || {}; - if ( !!opts['name'] ) + if ( is_string(opts) ) + { + fl = opts; opts = {}; + opts[fl] = v; fl = ''; + } + else + { + opts = opts || {}; + } + if ( !!opts['name'] || !!opts['named'] ) { self.g++; self.grp[self.g] = self.g; - self.grp[opts.name] = self.g; + self.grp[opts.name||opts.named] = self.g; } else if ( (true === opts['lookahead']) || (false === opts['lookahead']) ) { diff --git a/src/js/Regex.min.js b/src/js/Regex.min.js index abfebfa..5a938f8 100644 --- a/src/js/Regex.min.js +++ b/src/js/Regex.min.js @@ -1,10 +1,10 @@ /** * * Regex -* @version: 1.0.0 +* @version: 1.0.1 * * A simple & generic Regular Expression Analyzer & Composer for PHP, Python, Node/XPCOM/JS, Java, C/C++, ActionScript * https://github.com/foo123/RegexAnalyzer * **/ -!function(e,n,r){"use strict";"undefined"!=typeof Components&&"object"==typeof Components.classes&&"object"==typeof Components.classesByID&&Components.utils&&"function"==typeof Components.utils["import"]?(e.$deps=e.$deps||{})&&(e.EXPORTED_SYMBOLS=[n])&&(e[n]=e.$deps[n]=r.call(e)):"object"==typeof module&&module.exports?(module.$deps=module.$deps||{})&&(module.exports=module.$deps[n]=r.call(e)):"undefined"!=typeof System&&"function"==typeof System.register&&"function"==typeof System["import"]?System.register(n,[],function(t){t(n,r.call(e))}):"function"==typeof define&&define.amd&&"function"==typeof require&&"function"==typeof require.specified&&require.specified(n)?define(n,["module"],function(n){return r.moduleUri=n.uri,r.call(e)}):n in e||(e[n]=r.call(e)||1)&&"function"==typeof define&&define.amd&&define(function(){return e[n]})}(this,"Regex",function(e){"use strict";function n(e){return e instanceof Array||"[object Array]"===h.call(e)}function r(e){return e instanceof String||"[object String]"===h.call(e)}function t(e){return n(e)?e:[e]}function a(e,n){n=n||{};for(var r in e)g.call(e,r)&&(n[r]=e[r]);return n}function l(e){var n=this;n.re=e,n.len=e.length,n.pos=0,n.index=0,n.groupIndex=0,n.group={},n.inGroup=0}function u(e,n,r){var t=this;if(!(t instanceof u))return new u(e,n,r);switch(t.type=e,t.val=n,t.flags=r||{},e){case S:t.typeName="Sequence";break;case M:t.typeName="Alternation";break;case N:t.typeName="Group";break;case b:t.typeName="CharacterGroup";break;case R:t.typeName="Characters";break;case A:t.typeName="CharacterRange";break;case L:t.typeName="String";break;case k:t.typeName="Quantifier";break;case O:t.typeName="UnicodeChar";break;case I:t.typeName="HexChar";break;case E:t.typeName="Special";break;case j:t.typeName="Comment";break;default:t.typeName="unspecified"}}function o(e,n){return this instanceof o?void(e&&this.input(e,n)):new o(e,n)}function s(){var e=this;return e instanceof s?(e.re=null,void e.reset()):new s}var i="1.0.0",p="prototype",c=Object[p],f=Array[p],h=(Object.keys,c.toString),g=c.hasOwnProperty,v=String.fromCharCode,d="charAt",m="charCodeAt",y=(JSON.stringify,1/0),C="\\",G={".":"MatchAnyChar","|":"MatchEither","?":"MatchZeroOrOne","*":"MatchZeroOrMore","+":"MatchOneOrMore","^":"MatchStart",$:"MatchEnd","{":"StartRepeats","}":"EndRepeats","(":"StartGroup",")":"EndGroup","[":"StartCharGroup","]":"EndCharGroup"},x={"\\":"ESC","/":"/",0:"NULChar",f:"FormFeed",n:"LineFeed",r:"CarriageReturn",t:"HorizontalTab",v:"VerticalTab",b:"MatchWordBoundary",B:"MatchNonWordBoundary",s:"MatchSpaceChar",S:"MatchNonSpaceChar",w:"MatchWordChar",W:"MatchNonWordChar",d:"MatchDigitChar",D:"MatchNonDigitChar"},S=1,M=2,N=4,b=8,k=16,O=32,I=64,E=128,R=256,A=512,L=1024,j=2048;l[p]={constructor:l,re:null,len:null,pos:null,index:null,groupIndex:null,inGroup:null,groups:null,dispose:function(){var e=this;e.re=null,e.len=null,e.pos=null,e.index=null,e.groupIndex=null,e.group=null,e.inGroup=null}},u.toObjectStatic=function Ie(e){return e instanceof u?e.flags&&Object.keys(e.flags).length?{type:e.typeName,value:Ie(e.val),flags:e.flags}:{type:e.typeName,value:Ie(e.val)}:n(e)?e.map(Ie):e},u[p]={constructor:u,type:null,typeName:null,val:null,flags:null,dispose:function(){var e=this;return e.val=null,e.flags=null,e.type=null,e.typeName=null,e},toObject:function(){return u.toObjectStatic(this)}};var B=function(e,n){return Math.round((n-e)*Math.random()+e)},w=function(e,n){return new RegExp(e,n||"")},z=function(e){return f.slice.apply(e,f.slice.call(arguments,1))},D=function(e){for(var n=[],r=0;ru;)t=e[d](u++),a+=("-"===t||"^"===t||"$"===t||"|"===t||"{"===t||"}"===t||"("===t||")"===t||"["===t||"]"===t||"/"===t||n===t?n:"")+t;else for(;l>u;)t=e[d](u++),a+=("?"===t||"*"===t||"+"===t||"."===t||"^"===t||"$"===t||"|"===t||"{"===t||"}"===t||"("===t||")"===t||"["===t||"]"===t||"/"===t||n===t?n:"")+t;return a},$=function(e,n,r){var t=String(e);for(r=r||"0";t.length=t;++t)a.push(v(t));return a},Z=function(e,r){if(r){var t,a;if(n(r))for(t=0,a=r.length;a>t;t++)e[r[t]]=1;else for(t in r)g.call(r,t)&&(e[t]=1)}return e},q=" \x0B",V="~!@#$%^&*()-+=[]{}\\|;:,./<>?",H="0123456789",_=W(H),X=[_,[P("a"),P("f")],[P("A"),P("F")]],Y="_"+T("a","z").join("")+T("A","Z").join(""),J=q+V+H+Y,Q=J.split(""),K=function(e,n,r,t,a){r=r||0,t=t||1,a=a||y;for(var l,u=r,o=0,s=n.length;s>u&&a>=o&&-1=t?o:!1},ee=function(e,n,r,t,a){r=r||0,t=t||1,a=a||y;for(var l,u=r,o=0,s=n.length;s>u&&a>=o&&(l=n[m](u))>=e[0]&&l<=e[1];)u++,o++;return o>=t?o:!1},ne=function(e,n,r,t,a){r=r||0,t=t||1,a=a||y;for(var l,u,o,s=r,i=0,p=n.length,c=e.length,f=!0;p>s&&a>=i&&f;)for(l=n[m](s),f=!1,u=0;c>u;u++)if(o=e[u],l>=o[0]&&l<=o[1]){s++,i++,f=!0;break}return i>=t?i:!1},re=function(){return V[d](B(0,V.length-1))},te=function(e){return!1!==e?q[d](B(0,q.length-1)):(re()+ae()+le())[d](B(0,2))},ae=function(e){return!1!==e?H[d](B(0,H.length-1)):(re()+te()+le())[d](B(0,2))},le=function(e){return!1!==e?Y[d](B(0,Y.length-1)):(re()+te()+ae())[d](B(0,2))},ue=function(e){return!1!==e?(Y+H)[d](B(0,Y.length+H.length-1)):(re()+te())[d](B(0,1))},oe=function(){return J[d](B(0,J.length-1))},se=function(e,n){if(!1!==n)return e.length?e[B(0,e.length-1)]:"";var r=Q.filter(function(n){return 0>e.indexOf(n)});return r.length?r[B(0,r.length-1)]:""},ie=function(e){return.5a;a++)if(r.node=n,e=Ee(e,o[a],r),r.stop)return r.stop=null,e}else r.REDUCE&s&&(e=r.reduce(e,n,r));return r.node=null,e},fe=function(e,n,r){var a=n.type;if(M===a){for(var l=[],u=0,o=n.val.length-1;o>u;u++)l.push(n.val[u],"|");return l.push(n.val[o]),l}if(b===a)return[].concat("["+(n.flags.NegativeMatch?"^":"")).concat(t(n.val)).concat("]");if(k===a){var s="";return s=n.flags.MatchZeroOrOne?"?":n.flags.MatchZeroOrMore?"*":n.flags.MatchOneOrMore?"+":n.flags.min===n.flags.max?"{"+n.flags.min+"}":"{"+n.flags.min+","+(-1===n.flags.max?"":n.flags.max)+"}",n.flags.min===n.flags.max||n.flags.isGreedy||(s+="?"),[].concat(t(n.val)).concat(s)}if(N===a){var i=null;return i=n.flags.NotCaptured?[].concat("(?:").concat(t(n.val)).concat(")"):n.flags.LookAhead?[].concat("(?=").concat(t(n.val)).concat(")"):n.flags.NegativeLookAhead?[].concat("(?!").concat(t(n.val)).concat(")"):n.flags.LookBehind?[].concat("(?<=").concat(t(n.val)).concat(")"):n.flags.NegativeLookBehind?[].concat("(?=r.maxLength?a=n.flags.min:(l=n.flags.min,u=-1===n.flags.max?l+1+2*r.maxLength:n.flags.max,a=B(l,u)),a){o=new Array(a);for(var s=0;a>s;s++)o[s]=n.val;return o}return null}if(N===t&&n.flags.GroupIndex){var i=ce("",n.val,r);return r.group[n.flags.GroupIndex]=i,r.ret=i,null}return n.val},ge=function(e,n,r){var t=n.type;if(M===t){var a,l,u=n.val.length,o=u?ce(0,n.val[0],r):0;for(a=1;u>a;a++)l=ce(0,n.val[a],r),o>l&&(o=l);return u&&(r.ret=o),null}if(b===t)return n.val.length?n.val[0]:null;if(k===t){if(0===n.flags.min)return null;var a,s=n.flags.min,i=new Array(s);for(a=0;s>a;a++)i[a]=n.val;return i}if(N===t&&n.flags.GroupIndex){var o=ce(0,n.val,r);return r.group[n.flags.GroupIndex]=o,r.ret=o,null}return n.val},ve=function(e,n,r){var t=n.type;if(M===t){var a,l,u=n.val.length,o=u?ce(0,n.val[0],r):0;if(-1!==o)for(a=1;u>a;a++){if(l=ce(0,n.val[a],r),-1===l){o=-1;break}l>o&&(o=l)}return u&&(r.ret=o),null}if(b===t)return n.val.length?n.val[0]:null;if(k===t)return o=ce(0,n.val,r),-1===o?r.ret=-1:o>0&&(-1===n.flags.max?r.ret=-1:0u&&(a=n.val[u],l.push(a),k===a.type&&0===a.flags.min||E===a.type&&(a.flags.MatchStart||a.flags.MatchEnd));u++);return l.length?l:null}return n.val},me=function(e,n,r){if(null!=r.ret)return-1===r.ret?e=-1:e+=r.ret,e;if(-1===e)return e;if(n===+n)return e+=n;if(E===n.type&&n.flags.MatchEnd)return r.stop=1,e;var t=n.type;return R===t||A===t||O===t||I===t||E===t&&!n.flags.MatchStart&&!n.flags.MatchEnd?e+=n.flags.BackReference?r.group[n.flags.GroupIndex]||0:1:L===t&&(e+=n.val.length),e},ye=function(e,n,t){if(null!=t.ret)return e+=t.ret;if(r(n))return e+=n;if(E===n.type&&n.flags.MatchEnd)return t.stop=1,e;var a=n.type,l=null;if(R===a)l=n.val;else if(A===a){var u=[n.val[0],n.val[1]];O!==u[0].type&&I!==u[0].type||(u[0]=u[0].flags.Char),O!==u[1].type&&I!==u[1].type||(u[1]=u[1].flags.Char),l=T(u)}else if(O===a||I===a)l=[n.flags.Char];else if(E!==a||n.flags.MatchStart||n.flags.MatchEnd)L===a&&(l=n.val);else{var o=n.val;if(n.flags.BackReference)return e+=g.call(t.group,o)?t.group[o]:"";l="D"===o?[ae(!1)]:"W"===o?[ue(!1)]:"S"===o?[te(!1)]:"d"===o?[ae()]:"w"===o?[ue()]:"s"===o?[te()]:"."===o&&n.flags.MatchAnyChar?[oe()]:[C+o]}return l&&(e+=L===a?t.isCaseInsensitive?pe(l):l:se(t.isCaseInsensitive?pe(l,!0):l,!t.node||!t.node.flags.NegativeMatch)),e},Ce=function(e,n,t){if(null!=t.ret)return t.ret.src&&(e.src+=t.ret.src),t.ret.group&&(e.group=a(t.ret.group,e.group)),e;if(r(n))return e.src+=n,e;var l=n.type;if(R===l)e.src+=t.escaped?F(n.val.join(""),C,1):n.val.join("");else if(A===l){var u=[n.val[0],n.val[1]];t.escaped?(O===u[0].type?u[0]=C+"u"+$(u[0].flags.Code,4):I===u[0].type?u[0]=C+"x"+$(u[0].flags.Code,2):u[0]=F(u[0],C,1),O===u[1].type?u[1]=C+"u"+$(u[1].flags.Code,4):I===u[1].type?u[1]=C+"x"+$(u[1].flags.Code,2):u[1]=F(u[1],C,1)):(O!==u[0].type&&I!==u[0].type||(u[0]=u[0].flags.Char),O!==u[1].type&&I!==u[1].type||(u[1]=u[1].flags.Char)),e.src+=u[0]+"-"+u[1]}else O===l?e.src+=t.escaped?C+"u"+$(n.flags.Code,4):n.flags.Char:I===l?e.src+=t.escaped?C+"x"+$(n.flags.Code,2):n.flags.Char:E===l?n.flags.BackReference?e.src+=C+n.val:e.src+=n.flags.MatchStart||n.flags.MatchEnd?""+n.val:C+n.val:L===l&&(e.src+=t.escaped?F(n.val,C):n.val);return e},Ge=function(e,n,r){if(null!=r.ret)return e.positive=Z(e.positive,r.ret.positive),e.negative=Z(e.negative,r.ret.negative),e;if(E===n.type&&n.flags.MatchEnd)return r.stop=1,e;var t=n.type,a=r.node&&b===r.node.type,l=a&&r.node.flags.NegativeMatch,u=l?"negative":"positive";if(R===t)e[u]=Z(e[u],n.val);else if(A===t){var o=[n.val[0],n.val[1]];O!==o[0].type&&I!==o[0].type||(o[0]=o[0].flags.Char),O!==o[1].type&&I!==o[1].type||(o[1]=o[1].flags.Char),e[u]=Z(e[u],T(o))}else if(O===t||I===t)e[u][n.flags.Char]=1;else if(E!==t||n.flags.BackReference||n.flags.MatchStart||n.flags.MatchEnd)L===t&&(e.positive[n.val[d](0)]=1);else{var s=n.val;"D"===s?e[l?"positive":"negative"]["\\d"]=1:"W"===s?e[l?"positive":"negative"]["\\w"]=1:"S"===s?e[l?"positive":"negative"]["\\s"]=1:e[u][C+s]=1}return e},xe=function(e){var n=!1;return e.length>2&&"x"===e[d](0)&&ne(X,e,1,2,2)?[n=e.slice(0,3),n.slice(1)]:!1},Se=function(e){var n=!1;return e.length>4&&"u"===e[d](0)&&ne(X,e,1,4,4)?[n=e.slice(0,5),n.slice(1)]:!1},Me=function(e){var n,r=e.length,t=0,a=!1,l=!1;return r>2&&"{"===e[d](t)?(a=["","",null],t++,(n=K(q,e,t))&&(t+=n),(n=ee(_,e,t))?(a[1]=e.slice(t,t+n),t+=n,(n=K(q,e,t))&&(t+=n),r>t&&","===e[d](t)&&(t+=1,l=!0),(n=K(q,e,t))&&(t+=n),(n=ee(_,e,t))&&(a[2]=e.slice(t,t+n),t+=n),(n=K(q,e,t))&&(t+=n),r>t&&"}"===e[d](t)?(t++,a[0]=e.slice(0,t),l||(a[2]=a[1]),a):!1):!1):!1},Ne=function(e){var n,r,t,a,l,o,s,i,p=[],c=[],f=[],h={},m=!1,y=!1;for("^"===e.re[d](e.pos)&&(h.NegativeMatch=1,e.pos++),t=e.len;e.pos0){if(l=e.re.substr(e.pos,2),o=e.re.substr(e.pos,3),s=1,"?P="===o){for(h.BackReference=1,h.GroupName="",e.pos+=3,n=e.len;e.pos"!==r);)h.GroupName+=r;++e.index,s&&(++e.groupIndex,h.GroupIndex=e.groupIndex,e.group[h.GroupIndex]=h.GroupIndex,h.GroupName&&(e.group[h.GroupName]=h.GroupIndex))}for(n=e.len;e.pos="1"&&"9">=r){for(p&&(f.push(u(L,i)),i="",p=0),i=r;e.pos="0"&&"9">=r);)i+=r,e.pos++;a={},a.BackReference=1,a.GroupIndex=parseInt(i,10),f.push(u(E,i,a)),i=""}else i+=r,p+=1;else{if(e.inGroup>0&&")"===r)return p&&(f.push(u(L,i)),i="",p=0),c.length?(c.push(u(S,f)),f=[],a={},a[G["|"]]=1,u(N,u(M,c,a),h)):u(N,u(S,f),h);if("|"===r)p&&(f.push(u(L,i)),i="",p=0),c.push(u(S,f)),f=[];else if("["===r)p&&(f.push(u(L,i)),i="",p=0),f.push(Ne(e));else if("("===r)p&&(f.push(u(L,i)),i="",p=0),e.inGroup+=1,f.push(Re(e)),e.inGroup-=1;else if("{"===r){p&&(f.push(u(L,i)),i="",p=0),t=Me(e.re.substr(e.pos-1)),e.pos+=t[0].length-1,a={val:t[0],MatchMinimum:t[1],MatchMaximum:t[2]||"unlimited",min:parseInt(t[1],10),max:t[2]?parseInt(t[2],10):-1},a[G[r]]=1,e.pos1&&(f.push(u(L,y.val.slice(0,-1))),y.val=y.val.slice(-1)),f.push(u(k,y,a))}else if("*"===r||"+"===r||"?"===r){p&&(f.push(u(L,i)),i="",p=0),a={},a[G[r]]=1,a.min="+"===r?1:0,a.max="?"===r?1:-1,e.pos1&&(f.push(u(L,y.val.slice(0,-1))),y.val=y.val.slice(-1)),f.push(u(k,y,a))}else g.call(G,r)?(p&&(f.push(u(L,i)),i="",p=0),a={},a[G[r]]=1,f.push(u(E,r,a))):(i+=r,p+=1)}return p&&(f.push(u(L,i)),i="",p=0),c.length?(c.push(u(S,f)),f=[],a={},h[G["|"]]=1,u(M,c,a)):u(S,f)};o.VERSION=i,o[p]={constructor:o,ast:null,re:null,fl:null,src:null,grp:null,min:null,max:null,ch:null,dispose:function(){var e=this;return e.ast=null,e.re=null,e.fl=null,e.src=null,e.grp=null,e.min=null,e.max=null,e.ch=null,e},reset:function(){var e=this;return e.ast=null,e.src=null,e.grp=null,e.min=null,e.max=null,e.ch=null,e},input:function(e,n){var r=this;if(!arguments.length)return r.re;if(e){n=!1===n?!1:n||"/";var t,a,l={};if(e=e.toString(),t=e.length,n){for(;t>0&&(a=e[d](t-1),n!==a);)l[a]=1,t--;e=t>0?n===e[d](0)&&n===e[d](t-1)?e.slice(1,t-1):e.slice(0,t):""}r.re!==e&&r.reset(),r.re=e,r.fl=l}return r},analyze:function(){var e=this;if(null!=e.re&&null===e.ast){var n=new l(e.re);e.ast=be(n),n.dispose()}return e},synthesize:function(e){var n,r,t=this;return null==t.re?t:(null===t.ast&&(t.analyze(),t.src=null,t.grp=null),null===t.src&&(n={MAP:S|M|N|b|k,REDUCE:O|I|E|R|A|L,IGNORE:j,map:fe,reduce:Ce,escaped:!1!==e,group:{}},r=ce({src:"",group:{}},t.ast,n),t.src=r.src,t.grp=r.group),t)},source:function(){var e=this;return null==e.re?null:(null===e.src&&e.synthesize(),e.src)},groups:function(e){var n=this;return null==n.re?null:(null===n.grp&&n.synthesize(),!0===e?sel.grp:a(n.grp))},compile:function(e){var n=this;return null==n.re?null:(e=e||n.fl||{},new RegExp(n.source(),(e.g||e.G?"g":"")+(e.i||e.I?"i":"")+(e.m||e.M?"m":"")+(e.y||e.Y?"y":"")))},tree:function(e){var n=this;return null==n.re?null:(null===n.ast&&n.analyze(),!0===e?n.ast.toObject():n.ast)},sample:function(e,n){var r,t=this;if(null==t.re)return null;if(null===t.ast&&t.analyze(),r={MAP:S|M|N|b|k,REDUCE:O|I|E|R|A|L,IGNORE:j,map:he,reduce:ye,maxLength:0|e||1,isCaseInsensitive:null!=t.fl.i,group:{}},n=0|n||1,n>1){for(var a=new Array(n),l=0;n>l;l++)a[l]=ce("",t.ast,r);return a}return ce("",t.ast,r)},minimum:function(){var e,n=this;return null==n.re?0:(null===n.ast&&(n.analyze(),n.min=null),null===n.min&&(e={MAP:S|M|N|b|k,REDUCE:O|I|E|R|A|L,IGNORE:j,map:ge,reduce:me,group:{}},n.min=0|ce(0,n.ast,e)),n.min)},maximum:function(){var e,n=this;return null==n.re?0:(null===n.ast&&(n.analyze(),n.max=null),null===n.max&&(e={MAP:S|M|N|b|k,REDUCE:O|I|E|R|A|L,IGNORE:j,map:ve,reduce:me,group:{}},n.max=ce(0,n.ast,e)),n.max)},peek:function(){var e,n,r,t,l,u,o,s=this;if(null==s.re)return null;null===s.ast&&(s.analyze(),s.ch=null),null===s.ch&&(e={MAP:S|M|N|b|k,REDUCE:O|I|E|R|A|L,IGNORE:j,map:de,reduce:Ge,group:{}},s.ch=ce({positive:{},negative:{}},s.ast,e)),r={positive:a(s.ch.positive),negative:a(s.ch.negative)},n=null!=s.fl.i;for(t in r){o={},u=r[t];for(l in u)"\\d"===l?(delete u[l],o=Z(o,T("0","9"))):"\\s"===l?(delete u[l],o=Z(o,["\f","\n","\r"," ","\x0B"," ","\u2028","\u2029"])):"\\w"===l?(delete u[l],o=Z(o,["_"].concat(T("0","9")).concat(T("a","z")).concat(T("A","Z")))):"\\."===l?(delete u[l],o[G["."]]=1):C!==l[d](0)&&n?(o[l.toLowerCase()]=1,o[l.toUpperCase()]=1):C===l[d](0)&&delete u[l];r[t]=Z(u,o)}return r}},o[p].set=o[p].input,s.VERSION=i,s[p]={constructor:s,re:null,g:0,grp:null,level:0,ast:null,dispose:function(){var e=this;return e.re=null,e.g=null,e.grp=null,e.level=null,e.ast=null,e},reset:function(){var e=this;return e.g=0,e.grp={},e.level=0,e.ast=[{node:[],type:S,flag:""}],e},compose:function(){var e=this,n=z(arguments).join(""),r=e.ast[0].node.join("");return e.re={source:r,flags:n,groups:e.grp,pattern:w(r,n)},e.reset(),e.re},partial:function(e){var n=this,r=n.ast[0].node.join("");return!1!==e&&n.reset(),r},token:function(e,n){var r=this;return null!=e&&r.ast[r.level].node.push(!0===n?F(String(e),C):String(e)),r},literal:function(e){return this.token(e,!0)},regexp:function(e){return this.token(String(e),!1)},SOL:function(){var e=this;return e.ast[e.level].node.push("^"),e},SOF:function(){return this.SOL()},EOL:function(){var e=this;return e.ast[e.level].node.push("$"),e},EOF:function(){return this.EOL()},LF:function(){var e=this;return e.ast[e.level].node.push(C+"n"),e},CR:function(){var e=this;return e.ast[e.level].node.push(C+"r"),e},TAB:function(){var e=this;return e.ast[e.level].node.push(C+"t"),e},CTRL:function(e){var n=this;return n.ast[n.level].node.push(C+"c"+(e||0)),n},HEX:function(e){var n=this;return n.ast[n.level].node.push(C+"x"+$(e||0,2)),n},UNICODE:function(e){var n=this;return n.ast[n.level].node.push(C+"u"+$(e||0,4)),n},backSpace:function(){var e=this;return e.ast[e.level].node.push("["+C+"b]"),e},any:function(e){var n=this;return n.ast[n.level].node.push(!0===e?"["+C+"s"+C+"S]":"."),n},space:function(e){var n=this;return n.ast[n.level].node.push(!1===e?C+"S":C+"s"),n},digit:function(e){var n=this;return n.ast[n.level].node.push(!1===e?C+"D":C+"d"),n},word:function(e){var n=this;return n.ast[n.level].node.push(!1===e?C+"W":C+"w"),n},boundary:function(e){var n=this;return n.ast[n.level].node.push(!1===e?C+"B":C+"b"),n},characters:function(){var e=this;return b===e.ast[e.level].type&&e.ast[e.level].node.push(U(arguments,1).map(function(e){return F(String(e),C,1)}).join("")),e},range:function(e,n){var r=this;return null!=e&&null!=n&&b===r.ast[r.level].type&&r.ast[r.level].node.push(F(String(e),C,1)+"-"+F(String(n),C,1)),r},backReference:function(e){var n=this;return n.ast[n.level].node.push(C+(g.call(n.grp,e)?n.grp[e]:0|e)),n},repeat:function(e,n,r){var t=this;if(null==e)return t;var a=(null==n||e===n?"{"+String(e)+"}":"{"+String(e)+","+String(n)+"}")+(!1===r?"?":"");return t.ast[t.level].node[t.ast[t.level].node.length-1]+=a,t},zeroOrOne:function(e){var n=this;return n.ast[n.level].node[n.ast[n.level].node.length-1]+=!1===e?"??":"?",n},zeroOrMore:function(e){var n=this;return n.ast[n.level].node[n.ast[n.level].node.length-1]+=!1===e?"*?":"*",n},oneOrMore:function(e){var n=this;return n.ast[n.level].node[n.ast[n.level].node.length-1]+=!1===e?"+?":"+",n},alternate:function(){var e=this;return e.level++,e.ast.push({node:[],type:M,flag:""}),e},either:function(){return this.alternate()},group:function(e){var n=this,r=N,t="";return e=e||{},e.name?(n.g++,n.grp[n.g]=n.g,n.grp[e.name]=n.g):!0===e.lookahead||!1===e.lookahead?t=!1===e.lookahead?"?!":"?=":!0===e.lookbehind||!1===e.lookbehind?t=!1===e.lookbehind?"?u;)t=e[d](u++),a+=("-"===t||"^"===t||"$"===t||"|"===t||"{"===t||"}"===t||"("===t||")"===t||"["===t||"]"===t||"/"===t||n===t?n:"")+t;else for(;l>u;)t=e[d](u++),a+=("?"===t||"*"===t||"+"===t||"."===t||"^"===t||"$"===t||"|"===t||"{"===t||"}"===t||"("===t||")"===t||"["===t||"]"===t||"/"===t||n===t?n:"")+t;return a},$=function(e,n,r){var t=String(e);for(r=r||"0";t.length=t;++t)a.push(v(t));return a},Z=function(e,r){if(r){var t,a;if(n(r))for(t=0,a=r.length;a>t;t++)e[r[t]]=1;else for(t in r)g.call(r,t)&&(e[t]=1)}return e},q=" \x0B",V="~!@#$%^&*()-+=[]{}\\|;:,./<>?",H="0123456789",_=W(H),X=[_,[P("a"),P("f")],[P("A"),P("F")]],Y="_"+T("a","z").join("")+T("A","Z").join(""),J=q+V+H+Y,Q=J.split(""),K=function(e,n,r,t,a){r=r||0,t=t||1,a=a||y;for(var l,u=r,o=0,s=n.length;s>u&&a>=o&&-1=t?o:!1},ee=function(e,n,r,t,a){r=r||0,t=t||1,a=a||y;for(var l,u=r,o=0,s=n.length;s>u&&a>=o&&(l=n[m](u))>=e[0]&&l<=e[1];)u++,o++;return o>=t?o:!1},ne=function(e,n,r,t,a){r=r||0,t=t||1,a=a||y;for(var l,u,o,s=r,i=0,p=n.length,c=e.length,f=!0;p>s&&a>=i&&f;)for(l=n[m](s),f=!1,u=0;c>u;u++)if(o=e[u],l>=o[0]&&l<=o[1]){s++,i++,f=!0;break}return i>=t?i:!1},re=function(){return V[d](j(0,V.length-1))},te=function(e){return!1!==e?q[d](j(0,q.length-1)):(re()+ae()+le())[d](j(0,2))},ae=function(e){return!1!==e?H[d](j(0,H.length-1)):(re()+te()+le())[d](j(0,2))},le=function(e){return!1!==e?Y[d](j(0,Y.length-1)):(re()+te()+ae())[d](j(0,2))},ue=function(e){return!1!==e?(Y+H)[d](j(0,Y.length+H.length-1)):(re()+te())[d](j(0,1))},oe=function(){return J[d](j(0,J.length-1))},se=function(e,n){if(!1!==n)return e.length?e[j(0,e.length-1)]:"";var r=Q.filter(function(n){return 0>e.indexOf(n)});return r.length?r[j(0,r.length-1)]:""},ie=function(e){return.5a;a++)if(r.node=n,e=Ee(e,o[a],r),r.stop)return r.stop=null,e}else r.REDUCE&s&&(e=r.reduce(e,n,r));return r.node=null,e},fe=function(e,n,r){var a=n.type;if(S===a){for(var l=[],u=0,o=n.val.length-1;o>u;u++)l.push(n.val[u],"|");return l.push(n.val[o]),l}if(N===a)return[].concat("["+(n.flags.NegativeMatch?"^":"")).concat(t(n.val)).concat("]");if(k===a){var s="";return s=n.flags.MatchZeroOrOne?"?":n.flags.MatchZeroOrMore?"*":n.flags.MatchOneOrMore?"+":n.flags.min===n.flags.max?"{"+n.flags.min+"}":"{"+n.flags.min+","+(-1===n.flags.max?"":n.flags.max)+"}",n.flags.min===n.flags.max||n.flags.isGreedy||(s+="?"),[].concat(t(n.val)).concat(s)}if(b===a){var i=null;return i=n.flags.NotCaptured?[].concat("(?:").concat(t(n.val)).concat(")"):n.flags.LookAhead?[].concat("(?=").concat(t(n.val)).concat(")"):n.flags.NegativeLookAhead?[].concat("(?!").concat(t(n.val)).concat(")"):n.flags.LookBehind?[].concat("(?<=").concat(t(n.val)).concat(")"):n.flags.NegativeLookBehind?[].concat("(?=r.maxLength?a=n.flags.min:(l=n.flags.min,u=-1===n.flags.max?l+1+2*r.maxLength:n.flags.max,a=j(l,u)),a){o=new Array(a);for(var s=0;a>s;s++)o[s]=n.val;return o}return null}if(b===t&&n.flags.GroupIndex){var i=ce("",n.val,r);return r.group[n.flags.GroupIndex]=i,r.ret=i,null}return n.val},ge=function(e,n,r){var t=n.type;if(S===t){var a,l,u=n.val.length,o=u?ce(0,n.val[0],r):0;for(a=1;u>a;a++)l=ce(0,n.val[a],r),o>l&&(o=l);return u&&(r.ret=o),null}if(N===t)return n.val.length?n.val[0]:null;if(k===t){if(0===n.flags.min)return null;var a,s=n.flags.min,i=new Array(s);for(a=0;s>a;a++)i[a]=n.val;return i}if(b===t&&n.flags.GroupIndex){var o=ce(0,n.val,r);return r.group[n.flags.GroupIndex]=o,r.ret=o,null}return n.val},ve=function(e,n,r){var t=n.type;if(S===t){var a,l,u=n.val.length,o=u?ce(0,n.val[0],r):0;if(-1!==o)for(a=1;u>a;a++){if(l=ce(0,n.val[a],r),-1===l){o=-1;break}l>o&&(o=l)}return u&&(r.ret=o),null}if(N===t)return n.val.length?n.val[0]:null;if(k===t)return o=ce(0,n.val,r),-1===o?r.ret=-1:o>0&&(-1===n.flags.max?r.ret=-1:0u&&(a=n.val[u],l.push(a),k===a.type&&0===a.flags.min||E===a.type&&(a.flags.MatchStart||a.flags.MatchEnd));u++);return l.length?l:null}return n.val},me=function(e,n,r){if(null!=r.ret)return-1===r.ret?e=-1:e+=r.ret,e;if(-1===e)return e;if(n===+n)return e+=n;if(E===n.type&&n.flags.MatchEnd)return r.stop=1,e;var t=n.type;return R===t||A===t||O===t||I===t||E===t&&!n.flags.MatchStart&&!n.flags.MatchEnd?e+=n.flags.BackReference?r.group[n.flags.GroupIndex]||0:1:L===t&&(e+=n.val.length),e},ye=function(e,n,t){if(null!=t.ret)return e+=t.ret;if(r(n))return e+=n;if(E===n.type&&n.flags.MatchEnd)return t.stop=1,e;var a=n.type,l=null;if(R===a)l=n.val;else if(A===a){var u=[n.val[0],n.val[1]];O!==u[0].type&&I!==u[0].type||(u[0]=u[0].flags.Char),O!==u[1].type&&I!==u[1].type||(u[1]=u[1].flags.Char),l=T(u)}else if(O===a||I===a)l=[n.flags.Char];else if(E!==a||n.flags.MatchStart||n.flags.MatchEnd)L===a&&(l=n.val);else{var o=n.val;if(n.flags.BackReference)return e+=g.call(t.group,o)?t.group[o]:"";l="D"===o?[ae(!1)]:"W"===o?[ue(!1)]:"S"===o?[te(!1)]:"d"===o?[ae()]:"w"===o?[ue()]:"s"===o?[te()]:"."===o&&n.flags.MatchAnyChar?[oe()]:[C+o]}return l&&(e+=L===a?t.isCaseInsensitive?pe(l):l:se(t.isCaseInsensitive?pe(l,!0):l,!t.node||!t.node.flags.NegativeMatch)),e},Ce=function(e,n,t){if(null!=t.ret)return t.ret.src&&(e.src+=t.ret.src),t.ret.group&&(e.group=a(t.ret.group,e.group)),e;if(r(n))return e.src+=n,e;var l=n.type;if(R===l)e.src+=t.escaped?F(n.val.join(""),C,1):n.val.join("");else if(A===l){var u=[n.val[0],n.val[1]];t.escaped?(O===u[0].type?u[0]=C+"u"+$(u[0].flags.Code,4):I===u[0].type?u[0]=C+"x"+$(u[0].flags.Code,2):u[0]=F(u[0],C,1),O===u[1].type?u[1]=C+"u"+$(u[1].flags.Code,4):I===u[1].type?u[1]=C+"x"+$(u[1].flags.Code,2):u[1]=F(u[1],C,1)):(O!==u[0].type&&I!==u[0].type||(u[0]=u[0].flags.Char),O!==u[1].type&&I!==u[1].type||(u[1]=u[1].flags.Char)),e.src+=u[0]+"-"+u[1]}else O===l?e.src+=t.escaped?C+"u"+$(n.flags.Code,4):n.flags.Char:I===l?e.src+=t.escaped?C+"x"+$(n.flags.Code,2):n.flags.Char:E===l?n.flags.BackReference?e.src+=C+n.val:e.src+=n.flags.MatchAnyChar||n.flags.MatchStart||n.flags.MatchEnd?""+n.val:C+n.val:L===l&&(e.src+=t.escaped?F(n.val,C):n.val);return e},Ge=function(e,n,r){if(null!=r.ret)return e.positive=Z(e.positive,r.ret.positive),e.negative=Z(e.negative,r.ret.negative),e;if(E===n.type&&n.flags.MatchEnd)return r.stop=1,e;var t=n.type,a=r.node&&N===r.node.type,l=a&&r.node.flags.NegativeMatch,u=l?"negative":"positive";if(R===t)e[u]=Z(e[u],n.val);else if(A===t){var o=[n.val[0],n.val[1]];O!==o[0].type&&I!==o[0].type||(o[0]=o[0].flags.Char),O!==o[1].type&&I!==o[1].type||(o[1]=o[1].flags.Char),e[u]=Z(e[u],T(o))}else if(O===t||I===t)e[u][n.flags.Char]=1;else if(E!==t||n.flags.BackReference||n.flags.MatchStart||n.flags.MatchEnd)L===t&&(e.positive[n.val[d](0)]=1);else{var s=n.val;"D"===s?e[l?"positive":"negative"]["\\d"]=1:"W"===s?e[l?"positive":"negative"]["\\w"]=1:"S"===s?e[l?"positive":"negative"]["\\s"]=1:"B"===s?e[l?"positive":"negative"]["\\b"]=1:e[u][C+s]=1}return e},xe=function(e){var n=!1;return e.length>2&&"x"===e[d](0)&&ne(X,e,1,2,2)?[n=e.slice(0,3),n.slice(1)]:!1},Me=function(e){var n=!1;return e.length>4&&"u"===e[d](0)&&ne(X,e,1,4,4)?[n=e.slice(0,5),n.slice(1)]:!1},Se=function(e){var n,r=e.length,t=0,a=!1,l=!1;return r>2&&"{"===e[d](t)?(a=["","",null],t++,(n=K(q,e,t))&&(t+=n),(n=ee(_,e,t))?(a[1]=e.slice(t,t+n),t+=n,(n=K(q,e,t))&&(t+=n),r>t&&","===e[d](t)&&(t+=1,l=!0),(n=K(q,e,t))&&(t+=n),(n=ee(_,e,t))&&(a[2]=e.slice(t,t+n),t+=n),(n=K(q,e,t))&&(t+=n),r>t&&"}"===e[d](t)?(t++,a[0]=e.slice(0,t),l||(a[2]=a[1]),a):!1):!1):!1},be=function(e){var n,r,t,a,l,o,s,i,p=[],c=[],f=[],h={},m=!1,y=!1;for("^"===e.re[d](e.pos)&&(h.NegativeMatch=1,e.pos++),t=e.len;e.pos0){if(l=e.re.substr(e.pos,2),o=e.re.substr(e.pos,3),s=1,"?P="===o){for(h.BackReference=1,h.GroupName="",e.pos+=3,n=e.len;e.pos"!==r);)h.GroupName+=r;++e.index,s&&(++e.groupIndex,h.GroupIndex=e.groupIndex,e.group[h.GroupIndex]=h.GroupIndex,h.GroupName&&(e.group[h.GroupName]=h.GroupIndex))}for(n=e.len;e.pos="1"&&"9">=r){for(p&&(f.push(u(L,i)),i="",p=0),i=r;e.pos="0"&&"9">=r);)i+=r,e.pos++;a={},a.BackReference=1,a.GroupIndex=parseInt(i,10),f.push(u(E,i,a)),i=""}else i+=r,p+=1;else{if(e.inGroup>0&&")"===r)return p&&(f.push(u(L,i)),i="",p=0),c.length?(c.push(u(M,f)),f=[],a={},a[G["|"]]=1,u(b,u(S,c,a),h)):u(b,u(M,f),h);if("|"===r)p&&(f.push(u(L,i)),i="",p=0),c.push(u(M,f)),f=[];else if("["===r)p&&(f.push(u(L,i)),i="",p=0),f.push(be(e));else if("("===r)p&&(f.push(u(L,i)),i="",p=0),e.inGroup+=1,f.push(Re(e)),e.inGroup-=1;else if("{"===r){p&&(f.push(u(L,i)),i="",p=0),t=Se(e.re.substr(e.pos-1)),e.pos+=t[0].length-1,a={val:t[0],MatchMinimum:t[1],MatchMaximum:t[2]||"unlimited",min:parseInt(t[1],10),max:t[2]?parseInt(t[2],10):-1},a[G[r]]=1,e.pos1&&(f.push(u(L,y.val.slice(0,-1))),y.val=y.val.slice(-1)),f.push(u(k,y,a))}else if("*"===r||"+"===r||"?"===r){p&&(f.push(u(L,i)),i="",p=0),a={},a[G[r]]=1,a.min="+"===r?1:0,a.max="?"===r?1:-1,e.pos1&&(f.push(u(L,y.val.slice(0,-1))),y.val=y.val.slice(-1)),f.push(u(k,y,a))}else g.call(G,r)?(p&&(f.push(u(L,i)),i="",p=0),a={},a[G[r]]=1,f.push(u(E,r,a))):(i+=r,p+=1)}return p&&(f.push(u(L,i)),i="",p=0),c.length?(c.push(u(M,f)),f=[],a={},h[G["|"]]=1,u(S,c,a)):u(M,f)};o.VERSION=i,o[p]={constructor:o,ast:null,re:null,fl:null,src:null,grp:null,min:null,max:null,ch:null,dispose:function(){var e=this;return e.ast=null,e.re=null,e.fl=null,e.src=null,e.grp=null,e.min=null,e.max=null,e.ch=null,e},reset:function(){var e=this;return e.ast=null,e.src=null,e.grp=null,e.min=null,e.max=null,e.ch=null,e},input:function(e,n){var r=this;if(!arguments.length)return r.re;if(e){n=!1===n?!1:n||"/";var t,a,l={};if(e=e.toString(),t=e.length,n){for(;t>0&&(a=e[d](t-1),n!==a);)l[a]=1,t--;e=t>0?n===e[d](0)&&n===e[d](t-1)?e.slice(1,t-1):e.slice(0,t):""}r.re!==e&&r.reset(),r.re=e,r.fl=l}return r},analyze:function(){var e=this;if(null!=e.re&&null===e.ast){var n=new l(e.re);e.ast=Ne(n),n.dispose()}return e},synthesize:function(e){var n,r,t=this;return null==t.re?t:(null===t.ast&&(t.analyze(),t.src=null,t.grp=null),null===t.src&&(n={MAP:M|S|b|N|k,REDUCE:O|I|E|R|A|L,IGNORE:B,map:fe,reduce:Ce,escaped:!1!==e,group:{}},r=ce({src:"",group:{}},t.ast,n),t.src=r.src,t.grp=r.group),t)},source:function(){var e=this;return null==e.re?null:(null===e.src&&e.synthesize(),e.src)},groups:function(e){var n=this;return null==n.re?null:(null===n.grp&&n.synthesize(),!0===e?sel.grp:a(n.grp))},compile:function(e){var n=this;return null==n.re?null:(e=e||n.fl||{},new RegExp(n.source(),(e.g||e.G?"g":"")+(e.i||e.I?"i":"")+(e.m||e.M?"m":"")+(e.y||e.Y?"y":"")))},tree:function(e){var n=this;return null==n.re?null:(null===n.ast&&n.analyze(),!0===e?n.ast.toObject():n.ast)},sample:function(e,n){var r,t=this;if(null==t.re)return null;if(null===t.ast&&t.analyze(),r={MAP:M|S|b|N|k,REDUCE:O|I|E|R|A|L,IGNORE:B,map:he,reduce:ye,maxLength:0|e||1,isCaseInsensitive:null!=t.fl.i,group:{}},n=0|n||1,n>1){for(var a=new Array(n),l=0;n>l;l++)a[l]=ce("",t.ast,r);return a}return ce("",t.ast,r)},minimum:function(){var e,n=this;return null==n.re?0:(null===n.ast&&(n.analyze(),n.min=null),null===n.min&&(e={MAP:M|S|b|N|k,REDUCE:O|I|E|R|A|L,IGNORE:B,map:ge,reduce:me,group:{}},n.min=0|ce(0,n.ast,e)),n.min)},maximum:function(){var e,n=this;return null==n.re?0:(null===n.ast&&(n.analyze(),n.max=null),null===n.max&&(e={MAP:M|S|b|N|k,REDUCE:O|I|E|R|A|L,IGNORE:B,map:ve,reduce:me,group:{}},n.max=ce(0,n.ast,e)),n.max)},peek:function(){var e,n,r,t,l,u,o,s=this;if(null==s.re)return null;null===s.ast&&(s.analyze(),s.ch=null),null===s.ch&&(e={MAP:M|S|b|N|k,REDUCE:O|I|E|R|A|L,IGNORE:B,map:de,reduce:Ge,group:{}},s.ch=ce({positive:{},negative:{}},s.ast,e)),r={positive:a(s.ch.positive),negative:a(s.ch.negative)},n=null!=s.fl.i;for(t in r){o={},u=r[t];for(l in u)"\\d"===l?(delete u[l],o=Z(o,T("0","9"))):"\\s"===l?(delete u[l],o=Z(o,["\f","\n","\r"," ","\x0B"," ","\u2028","\u2029"])):"\\w"===l?(delete u[l],o=Z(o,["_"].concat(T("0","9")).concat(T("a","z")).concat(T("A","Z")))):"\\b"===l?(delete u[l],o[G.b]=1):"\\."===l?(delete u[l],o[G["."]]=1):C!==l[d](0)&&n?(o[l.toLowerCase()]=1,o[l.toUpperCase()]=1):C===l[d](0)&&delete u[l];r[t]=Z(u,o)}return r}},o[p].set=o[p].input,s.VERSION=i,s[p]={constructor:s,re:null,g:0,grp:null,level:0,ast:null,dispose:function(){var e=this;return e.re=null,e.g=null,e.grp=null,e.level=null,e.ast=null,e},reset:function(){var e=this;return e.g=0,e.grp={},e.level=0,e.ast=[{node:[],type:M,flag:""}],e},compose:function(){var e=this,n=z(arguments).join(""),r=e.ast[0].node.join("");return e.re={source:r,flags:n,groups:e.grp,pattern:w(r,n)},e.reset(),e.re},partial:function(e){var n=this,r=n.ast[0].node.join("");return!1!==e&&n.reset(),r},token:function(e,n){var r=this;return null!=e&&r.ast[r.level].node.push(!0===n?F(String(e),C):String(e)),r},literal:function(e){return this.token(e,!0)},regexp:function(e){return this.token(String(e),!1)},SOL:function(){var e=this;return e.ast[e.level].node.push("^"),e},SOF:function(){return this.SOL()},EOL:function(){var e=this;return e.ast[e.level].node.push("$"),e},EOF:function(){return this.EOL()},LF:function(){var e=this;return e.ast[e.level].node.push(C+"n"),e},CR:function(){var e=this;return e.ast[e.level].node.push(C+"r"),e},TAB:function(){var e=this;return e.ast[e.level].node.push(C+"t"),e},CTRL:function(e){var n=this;return n.ast[n.level].node.push(C+"c"+(e||0)),n},HEX:function(e){var n=this;return n.ast[n.level].node.push(C+"x"+$(e||0,2)),n},UNICODE:function(e){var n=this;return n.ast[n.level].node.push(C+"u"+$(e||0,4)),n},backSpace:function(){var e=this;return e.ast[e.level].node.push("["+C+"b]"),e},any:function(e){var n=this;return n.ast[n.level].node.push(!0===e?"["+C+"s"+C+"S]":"."),n},space:function(e){var n=this;return n.ast[n.level].node.push(!1===e?C+"S":C+"s"),n},digit:function(e){var n=this;return n.ast[n.level].node.push(!1===e?C+"D":C+"d"),n},word:function(e){var n=this;return n.ast[n.level].node.push(!1===e?C+"W":C+"w"),n},boundary:function(e){var n=this;return n.ast[n.level].node.push(!1===e?C+"B":C+"b"),n},characters:function(){var e=this;return N===e.ast[e.level].type&&e.ast[e.level].node.push(U(arguments,1).map(function(e){return F(String(e),C,1)}).join("")),e},range:function(e,n){var r=this;return null!=e&&null!=n&&N===r.ast[r.level].type&&r.ast[r.level].node.push(F(String(e),C,1)+"-"+F(String(n),C,1)),r},backReference:function(e){var n=this;return n.ast[n.level].node.push(C+(g.call(n.grp,e)?n.grp[e]:0|e)),n},repeat:function(e,n,r){var t=this;if(null==e)return t;var a=(null==n||e===n?"{"+String(e)+"}":"{"+String(e)+","+String(n)+"}")+(!1===r?"?":"");return t.ast[t.level].node[t.ast[t.level].node.length-1]+=a,t},zeroOrOne:function(e){var n=this;return n.ast[n.level].node[n.ast[n.level].node.length-1]+=!1===e?"??":"?",n},zeroOrMore:function(e){var n=this;return n.ast[n.level].node[n.ast[n.level].node.length-1]+=!1===e?"*?":"*",n},oneOrMore:function(e){var n=this;return n.ast[n.level].node[n.ast[n.level].node.length-1]+=!1===e?"+?":"+",n},alternate:function(){var e=this;return e.level++,e.ast.push({node:[],type:S,flag:""}),e},either:function(){return this.alternate()},group:function(e,n){var t=this,a=b,l="";return r(e)?(l=e,e={},e[l]=n,l=""):e=e||{},e.name||e.named?(t.g++,t.grp[t.g]=t.g,t.grp[e.name||e.named]=t.g):!0===e.lookahead||!1===e.lookahead?l=!1===e.lookahead?"?!":"?=":!0===e.lookbehind||!1===e.lookbehind?l=!1===e.lookbehind?"?src .= empty($node->flags->MatchStart) && empty($node->flags->MatchEnd) ? (Regex::ESC.$node->val) : (''.$node->val); + $ret->src .= isset($node->flags->MatchAnyChar) || isset($node->flags->MatchStart) || isset($node->flags->MatchEnd) ? (''.$node->val) : (Regex::ESC.$node->val); } } elseif ( Regex::T_STRING === $type ) @@ -857,6 +857,10 @@ private static function reduce_peek( $ret, &$node, &$state ) { $ret[$inNegativeCharGroup?"positive":"negative"][ '\\s' ] = 1; } + elseif ('B' === $part) + { + $ret[$inNegativeCharGroup?"positive":"negative"][ '\\b' ] = 1; + } else { $ret[$peek][Regex::ESC . $part] = 1; @@ -1689,6 +1693,12 @@ public function peek( ) )); } + else if ('\\b' === $c) + { + unset( $p[$c] ); + $cases[ $this->specialChars['b'] ] = 1; + } + else if ('\\.' === $c) { unset( $p[$c] ); @@ -1726,7 +1736,7 @@ public function peek( ) class RegexComposer { - const VERSION = "1.0.0"; + const VERSION = "1.0.1"; public $re = null; private $g = 0; @@ -1971,15 +1981,23 @@ public function either( ) return $this->alternate( ); } - public function group( $opts=array() ) + public function group( $opts=array(), $v=null ) { $type = Regex::T_GROUP; $fl = ''; - $opts = (array)$opts; - if ( isset($opts['name']) && strlen($opts['name']) ) + if ( is_string($opts) ) + { + $fl = $opts; $opts = array(); + $opts[$fl] = $v; $fl = ''; + } + else + { + $opts = (array)$opts; + } + if ( (isset($opts['name']) && strlen($opts['name'])) || (isset($opts['named']) && strlen($opts['named'])) ) { $this->g++; $this->grp[$this->g] = $this->g; - $this->grp[$opts['name']] = $this->g; + $this->grp[isset($opts['name']) ? $opts['name'] : $opts['named']] = $this->g; } elseif ( isset($opts['lookahead']) && ((true === $opts['lookahead']) || (false === $opts['lookahead'])) ) { @@ -2092,7 +2110,7 @@ public function endOfInput( ) } class Regex { - const VERSION = "1.0.0"; + const VERSION = "1.0.1"; const T_SEQUENCE = 1; const T_ALTERNATION = 2; const T_GROUP = 4; diff --git a/src/python/Regex.py b/src/python/Regex.py index 21a45e1..73bc440 100644 --- a/src/python/Regex.py +++ b/src/python/Regex.py @@ -2,7 +2,7 @@ ## # # Regex -# @version: 1.0.0 +# @version: 1.0.1 # # A simple & generic Regular Expression Analyzer & Composer for PHP, Python, Node/XPCOM/JS, Java, C/C++, ActionScript # https://github.com/foo123/Analyzer @@ -638,7 +638,7 @@ def reduce_src( ret, node, state ): if 'BackReference' in node.flags: ret['src'] += ESC+node.val else: - ret['src'] += ESC+node.val if ('MatchStart' not in node.flags) and ('MatchEnd' not in node.flags) else( ''+node.val) + ret['src'] += (''+node.val) if ('MatchAnyChar' in node.flags) or ('MatchStart' in node.flags) or ('MatchEnd' in node.flags) else (ESC+node.val) elif T_STRING == type: ret['src'] += esc_re(node.val, ESC) if state['escaped'] else node.val @@ -675,6 +675,8 @@ def reduce_peek( ret, node, state ): ret["positive" if inNegativeCharGroup else "negative"][ '\\w' ] = 1 elif 'S' == part: ret["positive" if inNegativeCharGroup else "negative"][ '\\s' ] = 1 + elif 'B' == part: + ret["positive" if inNegativeCharGroup else "negative"][ '\\b' ] = 1 else: ret[peek][ESC + part] = 1 elif T_STRING == type: @@ -1255,7 +1257,7 @@ def analyze_re( re_obj ): # http://php.net/manual/en/reference.pcre.pattern.syntax.php # A simple regular expression analyzer class Analyzer: - VERSION = "1.0.0" + VERSION = "1.0.1" def __init__(self, re=None, delim='/'): self.ast = None @@ -1481,6 +1483,11 @@ def peek( self ): del p[c] cases = concat(cases, ['_'] + character_range('0', '9') + character_range('a', 'z') + character_range('A', 'Z')) + elif '\\b' == c: + + del p[c] + cases[ _G.specialChars['b'] ] = 1 + elif '\\.' == c: @@ -1518,7 +1525,7 @@ def getArgs( args ): # A simple regular expression composer class Composer: - VERSION = "1.0.0" + VERSION = "1.0.1" def __init__( self ): self.re = None @@ -1683,9 +1690,15 @@ def alternate( self ): def either( self ): return self.alternate() - def group( self, opts=dict() ): + def group( self, opts=dict(), v=None ): type = T_GROUP fl = '' + if is_string(opts): + fl = opts + opts = {} + opts[fl] = v + fl = '' + if ('name' in opts) and len(str(opts['name'])): self.g += 1 self.grp[str(self.g)] = self.g @@ -1767,7 +1780,7 @@ class Regex: Regular Expressipn Analyzer and Composer for Python https://github.com/foo123/Analyzer """ - VERSION = "1.0.0" + VERSION = "1.0.1" Node = Node Analyzer = Analyzer Composer = Composer diff --git a/test/js/output.txt b/test/js/output.txt index aa62496..0602ea9 100644 --- a/test/js/output.txt +++ b/test/js/output.txt @@ -1,4 +1,4 @@ -Regex.VERSION = 1.0.0 +Regex.VERSION = 1.0.1 Testing Regex.Composer =============================================================== Partial : [_a-z][_a-z0-9]* @@ -115,43 +115,43 @@ Regular Expression Minimum / Maximum Length : Regular Expression Sample Match Strings : [ { - "sample": "DCCefghDCCe", + "sample": "cFGHc", "match": "yes", "groups": { - "1": "DCCe", - "named_group": "DCCe" + "1": "c", + "named_group": "c" } }, { - "sample": "dBFGHdB", + "sample": "cDEfghcDE", "match": "yes", "groups": { - "1": "dB", - "named_group": "dB" + "1": "cDE", + "named_group": "cDE" } }, { - "sample": "EbcfghEbc", + "sample": "EDcFGHEDc", "match": "yes", "groups": { - "1": "Ebc", - "named_group": "Ebc" + "1": "EDc", + "named_group": "EDc" } }, { - "sample": "cbfghcb", + "sample": "eBFGHeB", "match": "yes", "groups": { - "1": "cb", - "named_group": "cb" + "1": "eB", + "named_group": "eB" } }, { - "sample": "dAfghdA", + "sample": "cBFGHcB", "match": "yes", "groups": { - "1": "dA", - "named_group": "dA" + "1": "cB", + "named_group": "cB" } } ] diff --git a/test/php/output.txt b/test/php/output.txt index d1eefe8..3eaf6b2 100644 --- a/test/php/output.txt +++ b/test/php/output.txt @@ -1,4 +1,4 @@ -Regex.VERSION = 1.0.0 +Regex.VERSION = 1.0.1 Testing Regex.Composer =============================================================== Partial : [_a-z][_a-z0-9]* @@ -164,60 +164,60 @@ Array ( [0] => Array ( - [sample] => CFGHC + [sample] => EAbAFGHEAbA [match] => yes [groups] => Array ( - [1] => C - [named_group] => C + [1] => EAbA + [named_group] => EAbA ) ) [1] => Array ( - [sample] => aDfghaD + [sample] => dFGHd [match] => yes [groups] => Array ( - [1] => aD - [named_group] => aD + [1] => d + [named_group] => d ) ) [2] => Array ( - [sample] => AbeefghAbee + [sample] => eDBbFGHeDBb [match] => yes [groups] => Array ( - [1] => Abee - [named_group] => Abee + [1] => eDBb + [named_group] => eDBb ) ) [3] => Array ( - [sample] => EacfghEac + [sample] => eEBFGHeEB [match] => yes [groups] => Array ( - [1] => Eac - [named_group] => Eac + [1] => eEB + [named_group] => eEB ) ) [4] => Array ( - [sample] => aDDDFGHaDDD + [sample] => ddceFGHddce [match] => yes [groups] => Array ( - [1] => aDDD - [named_group] => aDDD + [1] => ddce + [named_group] => ddce ) ) diff --git a/test/python/output.txt b/test/python/output.txt index 27d88c2..936c455 100644 --- a/test/python/output.txt +++ b/test/python/output.txt @@ -1,5 +1,5 @@ Regex Module loaded succesfully -Regex.VERSION = 1.0.0 +Regex.VERSION = 1.0.1 Testing Regex.Composer =============================================================== Partial : [_a-z][_a-z0-9]* @@ -7,7 +7,7 @@ Composed : ^(?:[_a-z][_a-z0-9]*|(\*\*aabb\*\*)|.|\s|\D+)*?\1$ Expected : ^(?:[_a-z][_a-z0-9]*|(\*\*aabb\*\*)|.|\s|\D+)*?\1$ Output : { 'flags': 2, 'groups': {'1': 1, 'token': 1}, - 'pattern': <_sre.SRE_Pattern object at 0x0130C7E0>, + 'pattern': <_sre.SRE_Pattern object at 0x0127C6E8>, 'source': '^(?:[_a-z][_a-z0-9]*|(\\*\\*aabb\\*\\*)|.|\\s|\\D+)*?\\1$'} =============================================================== @@ -56,19 +56,19 @@ Regular Expression Minimum / Maximum Length : {'maximum': 'unlimited', 'minimum': 5} =============================================================== Regular Expression Sample Match Strings : -[ { 'groups': {'1': 'EeDA', 'named_group': 'EeDA'}, +[ { 'groups': {'1': 'BeD', 'named_group': 'BeD'}, 'match': 'yes', - 'sample': 'EeDAFGHEeDA'}, - { 'groups': {'1': 'cDBA', 'named_group': 'cDBA'}, + 'sample': 'BeDFGHBeD'}, + { 'groups': {'1': 'A', 'named_group': 'A'}, 'match': 'yes', - 'sample': 'cDBAfghcDBA'}, - { 'groups': {'1': 'AED', 'named_group': 'AED'}, + 'sample': 'AFGHA'}, + { 'groups': {'1': 'eeAc', 'named_group': 'eeAc'}, 'match': 'yes', - 'sample': 'AEDFGHAED'}, - { 'groups': {'1': 'cadA', 'named_group': 'cadA'}, + 'sample': 'eeAcFGHeeAc'}, + { 'groups': {'1': 'dbc', 'named_group': 'dbc'}, 'match': 'yes', - 'sample': 'cadAFGHcadA'}, - { 'groups': {'1': 'dC', 'named_group': 'dC'}, + 'sample': 'dbcFGHdbc'}, + { 'groups': {'1': 'Dbe', 'named_group': 'Dbe'}, 'match': 'yes', - 'sample': 'dCFGHdC'}] + 'sample': 'DbeFGHDbe'}] ===============================================================