From c9aa646761e458d0d6885af659929f3f23cfb9a8 Mon Sep 17 00:00:00 2001 From: Nikos M Date: Mon, 5 Dec 2016 17:36:35 +0200 Subject: [PATCH] v.0.6.0 (pre-release update, js-only) --- src/js/RegexAnalyzer.js | 225 +++++++++++++++++++++++------------- src/js/RegexAnalyzer.min.js | 2 +- test/js/output.txt | 75 ++++++++---- test/js/test.js | 20 ++-- 4 files changed, 208 insertions(+), 114 deletions(-) diff --git a/src/js/RegexAnalyzer.js b/src/js/RegexAnalyzer.js index 71687ea..89c3e4e 100644 --- a/src/js/RegexAnalyzer.js +++ b/src/js/RegexAnalyzer.js @@ -28,8 +28,7 @@ var __version__ = "0.6.0", PROTO = 'prototype', Obj = Object, Arr = Array, /*Str = String,*/ Keys = Obj.keys, to_string = Obj[PROTO].toString, fromCharCode = String.fromCharCode, CHAR = 'charAt', CHARCODE = 'charCodeAt', toJSON = JSON.stringify, - INF = Infinity, HAS = 'hasOwnProperty', - escapeChar = '\\', + INF = Infinity, HAS = 'hasOwnProperty', ESC = '\\', specialChars = { "." : "MatchAnyChar", "|" : "MatchEither", @@ -88,9 +87,20 @@ var __version__ = "0.6.0", T_SEQUENCE = 1, T_ALTERNATION = 2, T_GROUP = 3, T_QUANTIFIER = 4, T_UNICODECHAR = 5, T_HEXCHAR = 6, T_SPECIAL = 7, T_CHARGROUP = 8, T_CHARS = 9, - T_CHARRANGE = 10, T_STRING = 11, - escaped_re = /([.*+?^${}()|[\]\/\\\-])/g; + T_CHARRANGE = 10, T_STRING = 11; +function is_array( x ) +{ + return (x instanceof Array) || ('[object Array]' === to_string.call(x)); +} +function is_string( x ) +{ + return (x instanceof String) || ('[object String]' === to_string.call(x)); +} +function is_regexp( x ) +{ + return (x instanceof RegExp) || ('[object RegExp]' === to_string.call(x)); +} function clone( obj, cloned ) { cloned = cloned || {}; @@ -175,7 +185,34 @@ Node[PROTO] = { }; var rnd = function( a, b ){ return Math.round((b-a)*Math.random()+a); }, - esc_re = function( s ) { return s.replace(escaped_re, '\\$1'); }, + esc_re = function( s, esc, chargroup ) { + var es = '', l = s.length, i=0, c; + if ( chargroup ) + { + while( i < l ) + { + c = s[CHAR](i++); + //escaped_re = /([.*+?^${}()|[\]\/\\\-])/g + es += (('?' === c) || ('*' === c) || ('+' === c) || + ('-' === c) || ('^' === c) || ('$' === c) || ('|' === c) || + ('{' === c) || ('}' === c) || ('(' === c) || (')' === c) || + ('[' === c) || (']' === c) || ('/' === c) || (esc === c) ? esc : '') + c; + } + } + else + { + while( i < l ) + { + c = s[CHAR](i++); + //escaped_re = /([.*+?^${}()|[\]\/\\\-])/g + es += (('?' === c) || ('*' === c) || ('+' === c) || + ('.' === c) || ('^' === c) || ('$' === c) || ('|' === c) || + ('{' === c) || ('}' === c) || ('(' === c) || (')' === c) || + ('[' === c) || (']' === c) || ('/' === c) || (esc === c) ? esc : '') + c; + } + } + return es; + }, pad = function( s, n, z ) { var ps = String(s); z = z || '0'; @@ -187,11 +224,7 @@ var rnd = function( a, b ){ return Math.round((b-a)*Math.random()+a); }, //char_codes = function( s_or_a ) { return (s_or_a.substr ? s_or_a.split("") : s_or_a).map( char_code ); }, // http://stackoverflow.com/questions/12376870/create-an-array-of-characters-from-specified-range character_range = function(first, last) { - if ( first && ('function' === typeof(first.push)) ) - { - last = first[1]; - first = first[0]; - } + if ( first && is_array(first) ) { last = first[1]; first = first[0]; } var ch, chars, start = first[CHARCODE](0), end = last[CHARCODE](0); if ( end === start ) return [ fromCharCode( start ) ]; @@ -204,19 +237,13 @@ var rnd = function( a, b ){ return Math.round((b-a)*Math.random()+a); }, if ( p2 ) { var p, l; - if ( 'function' === typeof(p2.push) ) + if ( is_array(p2) ) { - for (p=0,l=p2.length; p 0 ) { pre = re_obj.re.substr(re_obj.pos, 2); + captured = 1; if ( "?:" === pre ) { flags[ "NotCaptured" ] = 1; re_obj.pos += 2; + captured = 0; } else if ( "?=" === pre ) { flags[ "LookAhead" ] = 1; re_obj.pos += 2; + captured = 0; } else if ( "?!" === pre ) { flags[ "NegativeLookAhead" ] = 1; re_obj.pos += 2; + captured = 0; } - // extended & custom regular expression features, not supported by default in all implementations - else if ( "?^" === pre ) + /*else if ( "?^" === pre ) { flags[ "NegativeMatch" ] = 1; re_obj.pos += 2; @@ -1007,7 +1049,8 @@ var rnd = function( a, b ){ return Math.round((b-a)*Math.random()+a); }, { flags[ "LookBehind" ] = 1; re_obj.pos += 2; - } + captured = 0; + }*/ else if ( "?<" === pre ) { @@ -1024,7 +1067,7 @@ var rnd = function( a, b ){ return Math.round((b-a)*Math.random()+a); }, } ++re_obj._groupIndex; - if ( !flags[ "NotCaptured" ] ) flags[ "GroupIndex" ] = ++re_obj.groupIndex; + if ( captured ) flags[ "GroupIndex" ] = ++re_obj.groupIndex; } lre = re_obj.len; @@ -1033,7 +1076,7 @@ var rnd = function( a, b ){ return Math.round((b-a)*Math.random()+a); }, ch = re_obj.re[CHAR]( re_obj.pos++ ); // \\abc - escaped = escapeChar === ch; + escaped = ESC === ch; if ( escaped ) ch = re_obj.re[CHAR]( re_obj.pos++ ); if ( escaped ) @@ -1256,7 +1299,7 @@ var rnd = function( a, b ){ return Math.round((b-a)*Math.random()+a); }, // A simple (js-flavored) regular expression analyzer var RegexAnalyzer = function RegexAnalyzer( re, delim ) { if ( !(this instanceof RegexAnalyzer) ) return new RegexAnalyzer(re, delim); - if ( re ) this.set( re, delim ); + if ( re ) this.input( re, delim ); }; RegexAnalyzer.VERSION = __version__; RegexAnalyzer.Node = Node; @@ -1298,13 +1341,16 @@ RegexAnalyzer[PROTO] = { return self; }, - set: function( re, delim ) { + input: function( re, delim ) { var self = this; + if ( !arguments.length ) return self.re; if ( re ) { delim = delim || '/'; + var src, l, ch, fl = {}; + src = is_regexp(re) ? re.source : null; re = re.toString( ); - var l = re.length, ch, fl = {}; + l = re.length; // parse re flags, if any while ( 0 < l ) @@ -1328,6 +1374,8 @@ RegexAnalyzer[PROTO] = { // re is different, reset the ast, etc if ( self.re !== re ) self.reset(); self.re = re; self.fl = fl; + // no need to reconstruct source, it is already regexp + if ( null !== src ) { self.src = src; self.grp = {}; } } return self; }, @@ -1338,9 +1386,9 @@ RegexAnalyzer[PROTO] = { return self; }, - build: function( escaped ) { + synthesize: function( escaped ) { var self = this, state, re; - if ( null == self.re ) return null; + if ( null == self.re ) return self; if ( null === self.ast ) { self.analyze( ); @@ -1357,19 +1405,32 @@ RegexAnalyzer[PROTO] = { re = walk({src:'',group:{}}, self.ast, state); self.src = re.src; self.grp = re.group; } - return {src:self.src, group:clone(self.grp)}; + return self; }, compile: function( flags ) { - var self = this, re, regexp; + var self = this, regexp; if ( null == self.re ) return null; flags = flags || self.fl || {}; - re = self.build(); - regexp = new RegExp(re.src, (flags.g||flags.G?'g':'')+(flags.i||flags.I?'i':'')+(flags.m||flags.M?'m':'')); - regexp.$group = re.group; + regexp = new RegExp(self.source(), (flags.g||flags.G?'g':'')+(flags.i||flags.I?'i':'')+(flags.m||flags.M?'m':'')); + regexp.$group = self.groups(); return regexp; }, + source: function( ) { + var self = this; + if ( null == self.re ) return null; + if ( null === self.src ) self.synthesize(); + return self.src; + }, + + groups: function( raw ) { + var self = this; + if ( null == self.re ) return null; + if ( null === self.grp ) self.synthesize(); + return true===raw ? sel.grp : clone(self.grp); + }, + tree: function( flat ) { var self = this; if ( null == self.re ) return null; @@ -1516,10 +1577,12 @@ RegexAnalyzer[PROTO] = { return peek; } }; +// alias +RegexAnalyzer[PROTO].set = RegexAnalyzer[PROTO].input; // custom method to access named groups feature, if any -RegExp.prototype.$group = null; -RegExp.prototype.group = function( group ){ +RegExp[PROTO].$group = null; +RegExp[PROTO].group = function( group ){ group = group || 0; return this.$group && this.$group.hasOwnProperty(group) ? this.$group[group] : group; }; diff --git a/src/js/RegexAnalyzer.min.js b/src/js/RegexAnalyzer.min.js index 64d5534..615539e 100644 --- a/src/js/RegexAnalyzer.min.js +++ b/src/js/RegexAnalyzer.min.js @@ -7,4 +7,4 @@ * https://github.com/foo123/RegexAnalyzer * **/ -!function(e,t,n){"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=[t])&&(e[t]=e.$deps[t]=n.call(e)):"object"==typeof module&&module.exports?(module.$deps=module.$deps||{})&&(module.exports=module.$deps[t]=n.call(e)):"undefined"!=typeof System&&"function"==typeof System.register&&"function"==typeof System["import"]?System.register(t,[],function(r){r(t,n.call(e))}):"function"==typeof define&&define.amd&&"function"==typeof require&&"function"==typeof require.specified&&require.specified(t)?define(t,["module"],function(t){return n.moduleUri=t.uri,n.call(e)}):t in e||(e[t]=n.call(e)||1)&&"function"==typeof define&&define.amd&&define(function(){return e[t]})}(this,"RegexAnalyzer",function(e){"use strict";function t(e,t){t=t||{};for(var n in e)e[i](n)&&(t[n]=e[n]);return t}var n="0.6.0",r="prototype",a=Object,l=(Array,a.keys,a[r].toString,String.fromCharCode),s="charAt",u="charCodeAt",o=(JSON.stringify,1/0),i="hasOwnProperty",p="\\",f={".":"MatchAnyChar","|":"MatchEither","?":"MatchZeroOrOne","*":"MatchZeroOrMore","+":"MatchOneOrMore","^":"MatchStart",$:"MatchEnd","{":"StartRepeats","}":"EndRepeats","(":"StartGroup",")":"EndGroup","[":"StartCharGroup","]":"EndCharGroup"},c={"\\":"EscapeChar","/":"/",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"},h=1,g=2,v=3,d=4,y=5,m=6,C=7,M=8,x=9,N=10,b=11,S=/([.*+?^${}()|[\]\/\\\-])/g,G=function(e){var t=this;t.re=e,t.len=e.length,t.pos=0,t._groupIndex=0,t.groupIndex=0,t.inGroup=0},O=function de(e,t,n){var r=this;if(!(r instanceof de))return new de(e,t,n);switch(r.type=e,r.val=t,r.flags=n||{},e){case h:r.typeName="Sequence";break;case g:r.typeName="Alternation";break;case v:r.typeName="Group";break;case M:r.typeName="CharacterGroup";break;case x:r.typeName="Characters";break;case N:r.typeName="CharacterRange";break;case b:r.typeName="String";break;case d:r.typeName="Quantifier";break;case y:r.typeName="UnicodeChar";break;case m:r.typeName="HexChar";break;case C:r.typeName="Special";break;default:r.typeName="unspecified"}};O.toObjectStatic=function ye(e){return e instanceof O?{type:e.typeName,value:ye(e.val),flags:e.flags}:e instanceof Array?e.map(ye):e},O[r]={constructor:O,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 O.toObjectStatic(this)}};var k=function(e,t){return Math.round((t-e)*Math.random()+e)},I=function(e){return e.replace(S,"\\$1")},E=function(e,t,n){var r=String(e);for(n=n||"0";r.length=n;++n)r.push(l(n));return r},L=function(e,t){if(t){var n,r;if("function"==typeof t.push)for(n=0,r=t.length;r>n;n++)e[t[n]]=1;else for(n in t)t[i](n)&&(e[n]=1)}return e},j=" \x0B",z="~!@#$%^&*()-+=[]{}\\|;:,./<>?",R="0123456789",B=w(R),D=[B,[A("a"),A("f")],[A("A"),A("F")]],W="_"+$("a","z").join("")+$("A","Z").join(""),Z=j+z+R+W,U=Z.split(""),_=function(e,t,n,r,a){n=n||0,r=r||1,a=a||o;for(var l,u=n,i=0,p=t.length;p>u&&a>=i&&-1=r?i:!1},q=function(e,t,n,r,a){n=n||0,r=r||1,a=a||o;for(var l,s=n,i=0,p=t.length;p>s&&a>=i&&(l=t[u](s))>=e[0]&&l<=e[1];)s++,i++;return i>=r?i:!1},F=function(e,t,n,r,a){n=n||0,r=r||1,a=a||o;for(var l,s,i,p=n,f=0,c=t.length,h=e.length,g=!0;c>p&&a>=f&&g;)for(l=t[u](p),g=!1,s=0;h>s;s++)if(i=e[s],l>=i[0]&&l<=i[1]){p++,f++,g=!0;break}return f>=r?f:!1},P=function(){return z[s](k(0,z.length-1))},T=function(e){return!1!==e?j[s](k(0,j.length-1)):(P()+H()+V())[s](k(0,2))},H=function(e){return!1!==e?R[s](k(0,R.length-1)):(P()+T()+V())[s](k(0,2))},V=function(e){return!1!==e?W[s](k(0,W.length-1)):(P()+T()+H())[s](k(0,2))},J=function(e){return!1!==e?(W+R)[s](k(0,W.length+R.length-1)):(P()+T())[s](k(0,1))},Q=function(){return Z[s](k(0,Z.length-1))},X=function(e,t){if(!1!==t)return e.length?e[k(0,e.length-1)]:"";var n=U.filter(function(t){return 0>e.indexOf(t)});return n.length?n[k(0,n.length-1)]:""},Y=function(e){return.5r;r++)if(n.node=t,e=me(e,l[r],n),n.stop)return n.stop=null,e}else x===s||N===s||y===s||m===s||C===s||b===s?e=n.reduce(e,t,n):null!=t&&(e=n.reduce(e,t,n));return n.node=null,e},te=function(e,t,n){var r,a=t.type;if(g===a){r=[];for(var l=0,s=t.val.length-1;s>l;l++)r.push(t.val[l],"|");return r.push(t.val[t.val.length-1]),r}if(M===a)return[].concat("["+(t.flags.NegativeMatch?"^":"")).concat(t.val).concat("]");if(d===a){var u="";return u=t.flags.MatchZeroOrOne?"?"+(t.flags.isGreedy?"":"?"):t.flags.MatchZeroOrMore?"*"+(t.flags.isGreedy?"":"?"):t.flags.MatchOneOrMore?"+"+(t.flags.isGreedy?"":"?"):"{"+t.flags.min+","+(-1===t.flags.max?"":t.flags.max)+"}",[].concat(t.val).concat(u)}return v===a?t.flags.LookBehind?null:(null!=t.flags.GroupIndex&&(e.group[t.flags.GroupIndex]=t.flags.GroupIndex,t.flags.GroupName&&(e.group[t.flags.GroupName]=t.flags.GroupIndex)),t.flags.NotCaptured?[].concat("(?:").concat(t.val).concat(")"):t.flags.LookAhead?[].concat("(?=").concat(t.val).concat(")"):t.flags.NegativeLookAhead?[].concat("(?!").concat(t.val).concat(")"):t.flags.NegativeMatch?[].concat("((?:").concat(t.val).concat(")|[\\s\\S]+)"):[].concat("(").concat(t.val).concat(")")):t.val},ne=function(e,t,n){var r=t.type;if(g===r||M===r)return t.val.length?t.val[k(0,t.val.length-1)]:null;if(d===r){var a,l,s,u;if(e.length>=n.maxLength?a=t.flags.min:(l=t.flags.min,s=-1===t.flags.max?l+1+2*n.maxLength:t.flags.max,a=k(l,s)),a){u=new Array(a);for(var o=0;a>o;o++)u[o]=t.val;return u}return null}return t.val},re=function(e,t,n){var r=t.type;if(g===r){var a,l,s=t.val.length,u=s?ee(0,t.val[0],n):0;for(a=1;s>a;a++)l=ee(0,t.val[a],n),u>l&&(u=l);return s&&(n.ret=u),null}if(M===r)return t.val.length?t.val[0]:null;if(d===r){if(0===t.flags.min)return null;var a,o=t.flags.min,i=new Array(o);for(a=0;o>a;a++)i[a]=t.val;return i}return t.val},ae=function(e,t,n){var r=t.type;if(g===r){var a,l,s=t.val.length,u=s?ee(0,t.val[0],n):0;if(-1!==u)for(a=1;s>a;a++){if(l=ee(0,t.val[a],n),-1===l){u=-1;break}l>u&&(u=l)}return s&&(n.ret=u),null}return M===r?t.val.length?t.val[0]:null:d===r?(u=ee(0,t.val,n),-1===u?n.ret=-1:u>0&&(-1===t.flags.max?n.ret=-1:0s&&(a=t.val[s],l.push(a),d===a.type&&0===a.flags.min||C===a.type&&(a.flags.MatchStart||a.flags.MatchEnd));s++);return l.length?l:null}return t.val},se=function(e,t,n){if(null!=n.ret)return-1===n.ret?e=-1:e+=n.ret,e;if(-1===e)return e;if(C===t.type&&t.flags.MatchEnd)return n.stop=1,e;var r=t.type;return x===r||N===r||y===r||m===r||C===r&&!t.flags.MatchStart&&!t.flags.MatchEnd?e+=1:b===r&&(e+=t.val.length),e},ue=function(e,t,n){if(null!=n.ret)return e+=n.ret;if(C===t.type&&t.flags.MatchEnd)return n.stop=1,e;var r=t.type,a=null;if(x===r)a=t.val;else if(N===r){var l=[t.val[0],t.val[1]];y!==l[0].type&&m!==l[0].type||(l[0]=l[0].flags.Char),y!==l[1].type&&m!==l[1].type||(l[1]=l[1].flags.Char),a=$(l)}else if(y===r||m===r)a=[t.flags.Char];else if(C!==r||t.flags.MatchStart||t.flags.MatchEnd)b===r&&(a=t.val);else{var s=t.val;a="D"===s?[H(!1)]:"W"===s?[J(!1)]:"S"===s?[T(!1)]:"d"===s?[H()]:"w"===s?[J()]:"s"===s?[T()]:"."===s&&t.flags.MatchAnyChar?[Q()]:["\\"+s]}return a&&(e+=b===r?n.isCaseInsensitive?K(a):a:X(n.isCaseInsensitive?K(a,!0):a,!n.node||!n.node.flags.NegativeMatch)),e},oe=function(e,n,r){if(null!=r.ret)return r.ret.src&&(e.src+=r.ret.src),r.ret.group&&(e.group=t(r.ret.group,e.group)),e;var a=n.type;if(x===a)e.src+=r.escaped?I(n.val.join("")):n.val.join("");else if(N===a){var l=[n.val[0],n.val[1]];r.escaped?(y===l[0].type?l[0]="\\u"+E(l[0].flags.Code,4):m===l[0].type?l[0]="\\x"+E(l[0].flags.Code,2):l[0]=I(l[0]),y===l[1].type?l[1]="\\u"+E(l[1].flags.Code,4):m===l[1].type?l[1]="\\x"+E(l[1].flags.Code,2):l[1]=I(l[1]),e.src+=l[0]+"-"+l[1]):(y!==l[0].type&&m!==l[0].type||(l[0]=l[0].flags.Char),y!==l[1].type&&m!==l[1].type||(l[1]=l[1].flags.Char),e.src+=l[0]+"-"+l[1])}else y===a?e.src+=r.escaped?"\\u"+E(n.flags.Code,4):n.flags.Char:m===a?e.src+=r.escaped?"\\x"+E(n.flags.Code,2):n.flags.Char:C===a?e.src+=n.flags.MatchStart||n.flags.MatchEnd?""+n.val:"\\"+n.val:b===a?e.src+=r.escaped?I(n.val):n.val:("string"==typeof n||n.substr)&&(e.src+=n);return e},ie=function(e,t,n){if(null!=n.ret)return e.positive=L(e.positive,n.ret.positive),e.negative=L(e.negative,n.ret.negative),e;if(C===t.type&&t.flags.MatchEnd)return n.stop=1,e;var r=t.type,a=n.node&&M===n.node.type,l=a&&n.node.flags.NegativeMatch,u=l?"negative":"positive";if(x===r)e[u]=L(e[u],t.val);else if(N===r){var o=[t.val[0],t.val[1]];y!==o[0].type&&m!==o[0].type||(o[0]=o[0].flags.Char),y!==o[1].type&&m!==o[1].type||(o[1]=o[1].flags.Char),e[u]=L(e[u],$(o))}else if(y===r||m===r)e[u][t.flags.Char]=1;else if(C!==r||t.flags.MatchStart||t.flags.MatchEnd)b===r&&(e.positive[t.val[s](0)]=1);else{var i=t.val;"D"===i?e[l?"positive":"negative"]["\\d"]=1:"W"===i?e[l?"positive":"negative"]["\\w"]=1:"S"===i?e[l?"positive":"negative"]["\\s"]=1:e[u]["\\"+i]=1}return e},pe=function(e){var t=!1;return e.length>2&&"x"===e[s](0)&&F(D,e,1,2,2)?[t=e.slice(0,3),t.slice(1)]:!1},fe=function(e){var t=!1;return e.length>4&&"u"===e[s](0)&&F(D,e,1,4,4)?[t=e.slice(0,5),t.slice(1)]:!1},ce=function(e){var t,n=e.length,r=0,a=!1,l=!1;return n>2&&"{"===e[s](r)?(a=["","",null],r++,(t=_(j,e,r))&&(r+=t),(t=q(B,e,r))?(a[1]=e.slice(r,r+t),r+=t,(t=_(j,e,r))&&(r+=t),n>r&&","===e[s](r)&&(r+=1,l=!0),(t=_(j,e,r))&&(r+=t),(t=q(B,e,r))&&(a[2]=e.slice(r,r+t),r+=t),(t=_(j,e,r))&&(r+=t),n>r&&"}"===e[s](r)?(r++,a[0]=e.slice(0,r),l||(a[2]=a[1]),a):!1):!1):!1},he=function(e){var t,n,r,a,u,o,f,h,g=[],v=[],d={},b=!1,S=!1;for("^"===e.re[s](e.pos)&&(d.NegativeMatch=1,e.pos++),r=e.len;e.pos0){if(u=e.re.substr(e.pos,2),"?:"===u)S.NotCaptured=1,e.pos+=2;else if("?="===u)S.LookAhead=1,e.pos+=2;else if("?!"===u)S.NegativeLookAhead=1,e.pos+=2;else if("?^"===u)S.NegativeMatch=1,e.pos+=2;else if("?&"===u)S.LookBehind=1,e.pos+=2;else if("?<"===u)for(S.NamedGroup=1,S.GroupName="",e.pos+=2,t=e.len;e.pos"!==n);)S.GroupName+=n;++e._groupIndex,S.NotCaptured||(S.GroupIndex=++e.groupIndex)}for(t=e.len;e.pos0&&")"===n)return M&&(N.push(O(b,o)),o="",M=0),x.length?(x.push(O(h,N)),N=[],a={},a[f["|"]]=1,O(v,O(g,x,a),S)):O(v,O(h,N),S);if("|"===n)M&&(N.push(O(b,o)),o="",M=0),x.push(O(h,N)),N=[];else if("["===n)M&&(N.push(O(b,o)),o="",M=0),N.push(he(e));else if("("===n)M&&(N.push(O(b,o)),o="",M=0),e.inGroup+=1,N.push(Ce(e)),e.inGroup-=1;else if("{"===n){M&&(N.push(O(b,o)),o="",M=0),r=ce(e.re.substr(e.pos-1)),e.pos+=r[0].length-1,a={val:r[0],MatchMinimum:r[1],MatchMaximum:r[2]||"unlimited",min:parseInt(r[1],10),max:r[2]?parseInt(r[2],10):-1},a[f[n]]=1,a.isGreedy=1;var k=N.pop();b===k.type&&k.val.length>1&&(N.push(O(b,k.val.slice(0,-1))),k.val=k.val.slice(-1)),N.push(O(d,k,a))}else if("*"===n||"+"===n||"?"===n){M&&(N.push(O(b,o)),o="",M=0),a={},a[f[n]]=1,a.min="+"===n?1:0,a.max="?"===n?1:-1,e.pos1&&(N.push(O(b,k.val.slice(0,-1))),k.val=k.val.slice(-1)),N.push(O(d,k,a))}else f[i](n)?(M&&(N.push(O(b,o)),o="",M=0),a={},a[f[n]]=1,N.push(O(C,n,a))):(o+=n,M+=1)}return M&&(N.push(O(b,o)),o="",M=0),x.length?(x.push(O(h,N)),N=[],a={},S[f["|"]]=1,O(g,x,a)):O(h,N)},ve=function Me(e,t){return this instanceof Me?void(e&&this.set(e,t)):new Me(e,t)};return ve.VERSION=n,ve.Node=O,ve.getCharRange=$,ve[r]={constructor:ve,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},set:function(e,t){var n=this;if(e){t=t||"/",e=e.toString();for(var r,a=e.length,l={};a>0&&(r=e[s](a-1),t!==r);)l[r]=1,a--;e=a>0?t===e[s](0)&&t===e[s](a-1)?e.slice(1,a-1):e.slice(0,a):"",n.re!==e&&n.reset(),n.re=e,n.fl=l}return n},analyze:function(){var e=this;return null!=e.re&&null===e.ast&&(e.ast=ge(new G(e.re))),e},build:function(e){var n,r,a=this;return null==a.re?null:(null===a.ast&&(a.analyze(),a.src=null,a.grp=null),null===a.src&&(n={map:te,reduce:oe,escaped:!1!==e},r=ee({src:"",group:{}},a.ast,n),a.src=r.src,a.grp=r.group),{src:a.src,group:t(a.grp)})},compile:function(e){var t,n,r=this;return null==r.re?null:(e=e||r.fl||{},t=r.build(),n=new RegExp(t.src,(e.g||e.G?"g":"")+(e.i||e.I?"i":"")+(e.m||e.M?"m":"")),n.$group=t.group,n)},tree:function(e){var t=this;return null==t.re?null:(null===t.ast&&t.analyze(),!0===e?t.ast.toObject():t.ast)},sample:function(e,t){var n,r=this;if(null==r.re)return null;if(null===r.ast&&r.analyze(),n={map:ne,reduce:ue,maxLength:0|e||1,isCaseInsensitive:null!=r.fl.i},t=0|t||1,t>1){for(var a=new Array(t),l=0;t>l;l++)a[l]=ee("",r.ast,n);return a}return ee("",r.ast,n)},minimum:function(){var e,t=this;return null==t.re?0:(null===t.ast&&(t.analyze(),t.min=null),null===t.min&&(e={map:re,reduce:se},t.min=0|ee(0,t.ast,e)),t.min)},maximum:function(){var e,t=this;return null==t.re?0:(null===t.ast&&(t.analyze(),t.max=null),null===t.max&&(e={map:ae,reduce:se},t.max=ee(0,t.ast,e)),t.max)},peek:function(){var e,n,r,a,l,u,o,i=this;if(null==i.re)return null;null===i.ast&&(i.analyze(),i.ch=null),null===i.ch&&(e={map:le,reduce:ie},i.ch=ee({positive:{},negative:{}},i.ast,e)),r={positive:t(i.ch.positive),negative:t(i.ch.negative)},n=null!=i.fl.i;for(a in r){o={},u=r[a];for(l in u)"\\d"===l?(delete u[l],o=L(o,$("0","9"))):"\\s"===l?(delete u[l],o=L(o,["\f","\n","\r"," ","\x0B"," ","\u2028","\u2029"])):"\\w"===l?(delete u[l],o=L(o,["_"].concat($("0","9")).concat($("a","z")).concat($("A","Z")))):"\\."===l?(delete u[l],o[f["."]]=1):"\\"!==l[s](0)&&n?(o[l.toLowerCase()]=1,o[l.toUpperCase()]=1):"\\"===l[s](0)&&delete u[l];r[a]=L(u,o)}return r}},RegExp.prototype.$group=null,RegExp.prototype.group=function(e){return e=e||0,this.$group&&this.$group.hasOwnProperty(e)?this.$group[e]:e},ve}); \ No newline at end of file +!function(e,n,t){"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]=t.call(e)):"object"==typeof module&&module.exports?(module.$deps=module.$deps||{})&&(module.exports=module.$deps[n]=t.call(e)):"undefined"!=typeof System&&"function"==typeof System.register&&"function"==typeof System["import"]?System.register(n,[],function(r){r(n,t.call(e))}):"function"==typeof define&&define.amd&&"function"==typeof require&&"function"==typeof require.specified&&require.specified(n)?define(n,["module"],function(n){return t.moduleUri=n.uri,t.call(e)}):n in e||(e[n]=t.call(e)||1)&&"function"==typeof define&&define.amd&&define(function(){return e[n]})}(this,"RegexAnalyzer",function(e){"use strict";function n(e){return e instanceof Array||"[object Array]"===o.call(e)}function t(e){return e instanceof String||"[object String]"===o.call(e)}function r(e){return e instanceof RegExp||"[object RegExp]"===o.call(e)}function a(e,n){n=n||{};for(var t in e)e[h](t)&&(n[t]=e[t]);return n}var l="0.6.0",u="prototype",s=Object,o=(Array,s.keys,s[u].toString),i=String.fromCharCode,c="charAt",f="charCodeAt",p=(JSON.stringify,1/0),h="hasOwnProperty",g="\\",v={".":"MatchAnyChar","|":"MatchEither","?":"MatchZeroOrOne","*":"MatchZeroOrMore","+":"MatchOneOrMore","^":"MatchStart",$:"MatchEnd","{":"StartRepeats","}":"EndRepeats","(":"StartGroup",")":"EndGroup","[":"StartCharGroup","]":"EndCharGroup"},d={"\\":"EscapeChar","/":"/",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"},m=1,y=2,C=3,x=4,M=5,N=6,b=7,S=8,G=9,O=10,E=11,I=function(e){var n=this;n.re=e,n.len=e.length,n.pos=0,n._groupIndex=0,n.groupIndex=0,n.inGroup=0},A=function Ce(e,n,t){var r=this;if(!(r instanceof Ce))return new Ce(e,n,t);switch(r.type=e,r.val=n,r.flags=t||{},e){case m:r.typeName="Sequence";break;case y:r.typeName="Alternation";break;case C:r.typeName="Group";break;case S:r.typeName="CharacterGroup";break;case G:r.typeName="Characters";break;case O:r.typeName="CharacterRange";break;case E:r.typeName="String";break;case x:r.typeName="Quantifier";break;case M:r.typeName="UnicodeChar";break;case N:r.typeName="HexChar";break;case b:r.typeName="Special";break;default:r.typeName="unspecified"}};A.toObjectStatic=function xe(e){return e instanceof A?{type:e.typeName,value:xe(e.val),flags:e.flags}:e instanceof Array?e.map(xe):e},A[u]={constructor:A,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 A.toObjectStatic(this)}};var k=function(e,n){return Math.round((n-e)*Math.random()+e)},w=function(e,n,t){var r,a="",l=e.length,u=0;if(t)for(;l>u;)r=e[c](u++),a+=("?"===r||"*"===r||"+"===r||"-"===r||"^"===r||"$"===r||"|"===r||"{"===r||"}"===r||"("===r||")"===r||"["===r||"]"===r||"/"===r||n===r?n:"")+r;else for(;l>u;)r=e[c](u++),a+=("?"===r||"*"===r||"+"===r||"."===r||"^"===r||"$"===r||"|"===r||"{"===r||"}"===r||"("===r||")"===r||"["===r||"]"===r||"/"===r||n===r?n:"")+r;return a},j=function(e,n,t){var r=String(e);for(t=t||"0";r.length=r;++r)a.push(i(r));return a},L=function(e,t){if(t){var r,a;if(n(t))for(r=0,a=t.length;a>r;r++)e[t[r]]=1;else for(r in t)t[h](r)&&(e[r]=1)}return e},B=" \x0B",D="~!@#$%^&*()-+=[]{}\\|;:,./<>?",W="0123456789",Z=z(W),U=[Z,[$("a"),$("f")],[$("A"),$("F")]],_="_"+R("a","z").join("")+R("A","Z").join(""),q=B+D+W+_,F=q.split(""),P=function(e,n,t,r,a){t=t||0,r=r||1,a=a||p;for(var l,u=t,s=0,o=n.length;o>u&&a>=s&&-1=r?s:!1},T=function(e,n,t,r,a){t=t||0,r=r||1,a=a||p;for(var l,u=t,s=0,o=n.length;o>u&&a>=s&&(l=n[f](u))>=e[0]&&l<=e[1];)u++,s++;return s>=r?s:!1},H=function(e,n,t,r,a){t=t||0,r=r||1,a=a||p;for(var l,u,s,o=t,i=0,c=n.length,h=e.length,g=!0;c>o&&a>=i&&g;)for(l=n[f](o),g=!1,u=0;h>u;u++)if(s=e[u],l>=s[0]&&l<=s[1]){o++,i++,g=!0;break}return i>=r?i:!1},V=function(){return D[c](k(0,D.length-1))},J=function(e){return!1!==e?B[c](k(0,B.length-1)):(V()+Q()+X())[c](k(0,2))},Q=function(e){return!1!==e?W[c](k(0,W.length-1)):(V()+J()+X())[c](k(0,2))},X=function(e){return!1!==e?_[c](k(0,_.length-1)):(V()+J()+Q())[c](k(0,2))},Y=function(e){return!1!==e?(_+W)[c](k(0,_.length+W.length-1)):(V()+J())[c](k(0,1))},K=function(){return q[c](k(0,q.length-1))},ee=function(e,n){if(!1!==n)return e.length?e[k(0,e.length-1)]:"";var t=F.filter(function(n){return 0>e.indexOf(n)});return t.length?t[k(0,t.length-1)]:""},ne=function(e){return.5a;a++)if(r.node=t,e=Me(e,u[a],r),r.stop)return r.stop=null,e}else G!==s&&O!==s&&M!==s&&N!==s&&b!==s&&E!==s||(e=r.reduce(e,t,r));return r.node=null,e},ae=function(e,n,t){var r,a=n.type;if(y===a){r=[];for(var l=0,u=n.val.length-1;u>l;l++)r.push(n.val[l],"|");return r.push(n.val[n.val.length-1]),r}if(S===a)return[].concat("["+(n.flags.NegativeMatch?"^":"")).concat(n.val).concat("]");if(x===a){var s="";return s=n.flags.MatchZeroOrOne?"?"+(n.flags.isGreedy?"":"?"):n.flags.MatchZeroOrMore?"*"+(n.flags.isGreedy?"":"?"):n.flags.MatchOneOrMore?"+"+(n.flags.isGreedy?"":"?"):n.flags.min===n.flags.max?"{"+n.flags.min+"}":"{"+n.flags.min+","+(-1===n.flags.max?"":n.flags.max)+"}",[].concat(n.val).concat(s)}if(C===a){var o=null;return o=n.flags.NotCaptured?[].concat("(?:").concat(n.val).concat(")"):n.flags.LookAhead?[].concat("(?=").concat(n.val).concat(")"):n.flags.NegativeLookAhead?[].concat("(?!").concat(n.val).concat(")"):[].concat("(").concat(n.val).concat(")"),null!=n.flags.GroupIndex&&(e.group[n.flags.GroupIndex]=n.flags.GroupIndex,n.flags.GroupName&&(e.group[n.flags.GroupName]=n.flags.GroupIndex)),o}return n.val},le=function(e,n,t){var r=n.type;if(y===r||S===r)return n.val.length?n.val[k(0,n.val.length-1)]:null;if(x===r){var a,l,u,s;if(e.length>=t.maxLength?a=n.flags.min:(l=n.flags.min,u=-1===n.flags.max?l+1+2*t.maxLength:n.flags.max,a=k(l,u)),a){s=new Array(a);for(var o=0;a>o;o++)s[o]=n.val;return s}return null}return n.val},ue=function(e,n,t){var r=n.type;if(y===r){var a,l,u=n.val.length,s=u?re(0,n.val[0],t):0;for(a=1;u>a;a++)l=re(0,n.val[a],t),s>l&&(s=l);return u&&(t.ret=s),null}if(S===r)return n.val.length?n.val[0]:null;if(x===r){if(0===n.flags.min)return null;var a,o=n.flags.min,i=new Array(o);for(a=0;o>a;a++)i[a]=n.val;return i}return n.val},se=function(e,n,t){var r=n.type;if(y===r){var a,l,u=n.val.length,s=u?re(0,n.val[0],t):0;if(-1!==s)for(a=1;u>a;a++){if(l=re(0,n.val[a],t),-1===l){s=-1;break}l>s&&(s=l)}return u&&(t.ret=s),null}return S===r?n.val.length?n.val[0]:null:x===r?(s=re(0,n.val,t),-1===s?t.ret=-1:s>0&&(-1===n.flags.max?t.ret=-1:0u&&(a=n.val[u],l.push(a),x===a.type&&0===a.flags.min||b===a.type&&(a.flags.MatchStart||a.flags.MatchEnd));u++);return l.length?l:null}return n.val},ie=function(e,n,t){if(null!=t.ret)return-1===t.ret?e=-1:e+=t.ret,e;if(-1===e)return e;if(b===n.type&&n.flags.MatchEnd)return t.stop=1,e;var r=n.type;return G===r||O===r||M===r||N===r||b===r&&!n.flags.MatchStart&&!n.flags.MatchEnd?e+=1:E===r&&(e+=n.val.length),e},ce=function(e,n,t){if(null!=t.ret)return e+=t.ret;if(b===n.type&&n.flags.MatchEnd)return t.stop=1,e;var r=n.type,a=null;if(G===r)a=n.val;else if(O===r){var l=[n.val[0],n.val[1]];M!==l[0].type&&N!==l[0].type||(l[0]=l[0].flags.Char),M!==l[1].type&&N!==l[1].type||(l[1]=l[1].flags.Char),a=R(l)}else if(M===r||N===r)a=[n.flags.Char];else if(b!==r||n.flags.MatchStart||n.flags.MatchEnd)E===r&&(a=n.val);else{var u=n.val;a="D"===u?[Q(!1)]:"W"===u?[Y(!1)]:"S"===u?[J(!1)]:"d"===u?[Q()]:"w"===u?[Y()]:"s"===u?[J()]:"."===u&&n.flags.MatchAnyChar?[K()]:["\\"+u]}return a&&(e+=E===r?t.isCaseInsensitive?te(a):a:ee(t.isCaseInsensitive?te(a,!0):a,!t.node||!t.node.flags.NegativeMatch)),e},fe=function(e,n,r){if(null!=r.ret)return r.ret.src&&(e.src+=r.ret.src),r.ret.group&&(e.group=a(r.ret.group,e.group)),e;if(t(n))return e.src+=n,e;var l=n.type;if(G===l)e.src+=r.escaped?w(n.val.join(""),g,1):n.val.join("");else if(O===l){var u=[n.val[0],n.val[1]];r.escaped?(M===u[0].type?u[0]="\\u"+j(u[0].flags.Code,4):N===u[0].type?u[0]="\\x"+j(u[0].flags.Code,2):u[0]=w(u[0],g,1),M===u[1].type?u[1]="\\u"+j(u[1].flags.Code,4):N===u[1].type?u[1]="\\x"+j(u[1].flags.Code,2):u[1]=w(u[1],g,1),e.src+=u[0]+"-"+u[1]):(M!==u[0].type&&N!==u[0].type||(u[0]=u[0].flags.Char),M!==u[1].type&&N!==u[1].type||(u[1]=u[1].flags.Char),e.src+=u[0]+"-"+u[1])}else M===l?e.src+=r.escaped?"\\u"+j(n.flags.Code,4):n.flags.Char:N===l?e.src+=r.escaped?"\\x"+j(n.flags.Code,2):n.flags.Char:b===l?e.src+=n.flags.MatchStart||n.flags.MatchEnd?""+n.val:"\\"+n.val:E===l&&(e.src+=r.escaped?w(n.val,g):n.val);return e},pe=function(e,n,t){if(null!=t.ret)return e.positive=L(e.positive,t.ret.positive),e.negative=L(e.negative,t.ret.negative),e;if(b===n.type&&n.flags.MatchEnd)return t.stop=1,e;var r=n.type,a=t.node&&S===t.node.type,l=a&&t.node.flags.NegativeMatch,u=l?"negative":"positive";if(G===r)e[u]=L(e[u],n.val);else if(O===r){var s=[n.val[0],n.val[1]];M!==s[0].type&&N!==s[0].type||(s[0]=s[0].flags.Char),M!==s[1].type&&N!==s[1].type||(s[1]=s[1].flags.Char),e[u]=L(e[u],R(s))}else if(M===r||N===r)e[u][n.flags.Char]=1;else if(b!==r||n.flags.MatchStart||n.flags.MatchEnd)E===r&&(e.positive[n.val[c](0)]=1);else{var o=n.val;"D"===o?e[l?"positive":"negative"]["\\d"]=1:"W"===o?e[l?"positive":"negative"]["\\w"]=1:"S"===o?e[l?"positive":"negative"]["\\s"]=1:e[u]["\\"+o]=1}return e},he=function(e){var n=!1;return e.length>2&&"x"===e[c](0)&&H(U,e,1,2,2)?[n=e.slice(0,3),n.slice(1)]:!1},ge=function(e){var n=!1;return e.length>4&&"u"===e[c](0)&&H(U,e,1,4,4)?[n=e.slice(0,5),n.slice(1)]:!1},ve=function(e){var n,t=e.length,r=0,a=!1,l=!1;return t>2&&"{"===e[c](r)?(a=["","",null],r++,(n=P(B,e,r))&&(r+=n),(n=T(Z,e,r))?(a[1]=e.slice(r,r+n),r+=n,(n=P(B,e,r))&&(r+=n),t>r&&","===e[c](r)&&(r+=1,l=!0),(n=P(B,e,r))&&(r+=n),(n=T(Z,e,r))&&(a[2]=e.slice(r,r+n),r+=n),(n=P(B,e,r))&&(r+=n),t>r&&"}"===e[c](r)?(r++,a[0]=e.slice(0,r),l||(a[2]=a[1]),a):!1):!1):!1},de=function(e){var n,t,r,a,l,u,s,o,f=[],p=[],v=[],m={},y=!1,C=!1;for("^"===e.re[c](e.pos)&&(m.NegativeMatch=1,e.pos++),r=e.len;e.pos0){if(l=e.re.substr(e.pos,2),u=1,"?:"===l)S.NotCaptured=1,e.pos+=2,u=0;else if("?="===l)S.LookAhead=1,e.pos+=2,u=0;else if("?!"===l)S.NegativeLookAhead=1,e.pos+=2,u=0;else if("?<"===l)for(S.NamedGroup=1,S.GroupName="",e.pos+=2,n=e.len;e.pos"!==t);)S.GroupName+=t;++e._groupIndex,u&&(S.GroupIndex=++e.groupIndex)}for(n=e.len;e.pos0&&")"===t)return o&&(p.push(A(E,s)),s="",o=0),f.length?(f.push(A(m,p)),p=[],a={},a[v["|"]]=1,A(C,A(y,f,a),S)):A(C,A(m,p),S);if("|"===t)o&&(p.push(A(E,s)),s="",o=0),f.push(A(m,p)),p=[];else if("["===t)o&&(p.push(A(E,s)),s="",o=0),p.push(de(e));else if("("===t)o&&(p.push(A(E,s)),s="",o=0),e.inGroup+=1,p.push(Ne(e)),e.inGroup-=1;else if("{"===t){o&&(p.push(A(E,s)),s="",o=0),r=ve(e.re.substr(e.pos-1)),e.pos+=r[0].length-1,a={val:r[0],MatchMinimum:r[1],MatchMaximum:r[2]||"unlimited",min:parseInt(r[1],10),max:r[2]?parseInt(r[2],10):-1},a[v[t]]=1,a.isGreedy=1;var O=p.pop();E===O.type&&O.val.length>1&&(p.push(A(E,O.val.slice(0,-1))),O.val=O.val.slice(-1)),p.push(A(x,O,a))}else if("*"===t||"+"===t||"?"===t){o&&(p.push(A(E,s)),s="",o=0),a={},a[v[t]]=1,a.min="+"===t?1:0,a.max="?"===t?1:-1,e.pos1&&(p.push(A(E,O.val.slice(0,-1))),O.val=O.val.slice(-1)),p.push(A(x,O,a))}else v[h](t)?(o&&(p.push(A(E,s)),s="",o=0),a={},a[v[t]]=1,p.push(A(b,t,a))):(s+=t,o+=1)}return o&&(p.push(A(E,s)),s="",o=0),f.length?(f.push(A(m,p)),p=[],a={},S[v["|"]]=1,A(y,f,a)):A(m,p)},ye=function be(e,n){return this instanceof be?void(e&&this.input(e,n)):new be(e,n)};return ye.VERSION=l,ye.Node=A,ye.getCharRange=R,ye[u]={constructor:ye,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 t=this;if(!arguments.length)return t.re;if(e){n=n||"/";var a,l,u,s={};for(a=r(e)?e.source:null,e=e.toString(),l=e.length;l>0&&(u=e[c](l-1),n!==u);)s[u]=1,l--;e=l>0?n===e[c](0)&&n===e[c](l-1)?e.slice(1,l-1):e.slice(0,l):"",t.re!==e&&t.reset(),t.re=e,t.fl=s,null!==a&&(t.src=a,t.grp={})}return t},analyze:function(){var e=this;return null!=e.re&&null===e.ast&&(e.ast=me(new I(e.re))),e},synthesize:function(e){var n,t,r=this;return null==r.re?r:(null===r.ast&&(r.analyze(),r.src=null,r.grp=null),null===r.src&&(n={map:ae,reduce:fe,escaped:!1!==e},t=re({src:"",group:{}},r.ast,n),r.src=t.src,r.grp=t.group),r)},compile:function(e){var n,t=this;return null==t.re?null:(e=e||t.fl||{},n=new RegExp(t.source(),(e.g||e.G?"g":"")+(e.i||e.I?"i":"")+(e.m||e.M?"m":"")),n.$group=t.groups(),n)},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))},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 t,r=this;if(null==r.re)return null;if(null===r.ast&&r.analyze(),t={map:le,reduce:ce,maxLength:0|e||1,isCaseInsensitive:null!=r.fl.i},n=0|n||1,n>1){for(var a=new Array(n),l=0;n>l;l++)a[l]=re("",r.ast,t);return a}return re("",r.ast,t)},minimum:function(){var e,n=this;return null==n.re?0:(null===n.ast&&(n.analyze(),n.min=null),null===n.min&&(e={map:ue,reduce:ie},n.min=0|re(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:se,reduce:ie},n.max=re(0,n.ast,e)),n.max)},peek:function(){var e,n,t,r,l,u,s,o=this;if(null==o.re)return null;null===o.ast&&(o.analyze(),o.ch=null),null===o.ch&&(e={map:oe,reduce:pe},o.ch=re({positive:{},negative:{}},o.ast,e)),t={positive:a(o.ch.positive),negative:a(o.ch.negative)},n=null!=o.fl.i;for(r in t){s={},u=t[r];for(l in u)"\\d"===l?(delete u[l],s=L(s,R("0","9"))):"\\s"===l?(delete u[l],s=L(s,["\f","\n","\r"," ","\x0B"," ","\u2028","\u2029"])):"\\w"===l?(delete u[l],s=L(s,["_"].concat(R("0","9")).concat(R("a","z")).concat(R("A","Z")))):"\\."===l?(delete u[l],s[v["."]]=1):"\\"!==l[c](0)&&n?(s[l.toLowerCase()]=1,s[l.toUpperCase()]=1):"\\"===l[c](0)&&delete u[l];t[r]=L(u,s)}return t}},ye[u].set=ye[u].input,RegExp[u].$group=null,RegExp[u].group=function(e){return e=e||0,this.$group&&this.$group.hasOwnProperty(e)?this.$group[e]:e},ye}); \ No newline at end of file diff --git a/test/js/output.txt b/test/js/output.txt index 08764e6..eb1d109 100644 --- a/test/js/output.txt +++ b/test/js/output.txt @@ -7,9 +7,10 @@ Expected: /^([_a-z][_a-z0-9]*|\*\*aabb\*\*|.|\s|\D+)*?$/i Testing Analyzer.VERSION = 0.6.0 ========================================= -Input : /(?[abc\u0012]+)\x12/gi -Regular Expression : (?[abc\u0012]+)\x12 +Input : /(?[ab\u0012cde]+)\x12/gi +Regular Expression : (?[ab\u0012cde]+)\x12 Regular Expression Flags : i,g +Regular Expression Reconstructed : ([\u0012abcde]+)\x12 ============================================= Regular Expression Syntax Tree : { @@ -25,15 +26,6 @@ Regular Expression Syntax Tree : "value": { "type": "CharacterGroup", "value": [ - { - "type": "Characters", - "value": [ - "a", - "b", - "c" - ], - "flags": {} - }, { "type": "UnicodeChar", "value": "u0012", @@ -41,6 +33,17 @@ Regular Expression Syntax Tree : "Char": "\u0012", "Code": "0012" } + }, + { + "type": "Characters", + "value": [ + "a", + "b", + "c", + "d", + "e" + ], + "flags": {} } ], "flags": {} @@ -73,8 +76,6 @@ Regular Expression Syntax Tree : "flags": {} } ============================================= -Regular Expression Reconstructed Source : ([abc\u0012]+)\x12 -============================================= Regular Expression (Named) Matched Groups : { "1": 1, @@ -84,13 +85,17 @@ Regular Expression (Named) Matched Groups : Regular Expression Peek Characters : { "positive": [ + "\u0012", "a", "b", "c", - "\u0012", + "d", + "e", "A", "B", - "C" + "C", + "D", + "E" ], "negative": [] } @@ -104,24 +109,44 @@ Regular Expression Minimum / Maximum Length : Regular Expression Sample Match Strings : [ { - "sample": "\u0012a\u0012", - "match": "yes" + "sample": "c\u0012", + "match": "yes", + "groups": { + "1": "c", + "named_group": "c" + } }, { - "sample": "\u0012\u0012\u0012\u0012", - "match": "no" + "sample": "Db\u0012", + "match": "yes", + "groups": { + "1": "Db", + "named_group": "Db" + } }, { - "sample": "\u0012\u0012", - "match": "yes" + "sample": "AB\u0012\u0012", + "match": "yes", + "groups": { + "1": "AB\u0012", + "named_group": "AB\u0012" + } }, { - "sample": "\u0012\u0012\u0012", - "match": "no" + "sample": "d\u0012\u0012a\u0012", + "match": "yes", + "groups": { + "1": "d\u0012\u0012a", + "named_group": "d\u0012\u0012a" + } }, { - "sample": "\u0012\u0012C\u0012\u0012", - "match": "yes" + "sample": "bb\u0012\u0012", + "match": "yes", + "groups": { + "1": "bb\u0012", + "named_group": "bb\u0012" + } } ] ============================================= diff --git a/test/js/test.js b/test/js/test.js index d837822..7176191 100644 --- a/test/js/test.js +++ b/test/js/test.js @@ -58,7 +58,7 @@ echo("================"); echo(); var Analyzer = require('../../src/js/RegexAnalyzer.js'), - anal, peekChars, sampleStr, minLen, maxLen, regexp, inregex = /*process.argv[2] || /xyz([abc0-9]){2,3}/i*/"/(?[abc\\u0012]+)\\x12/gi" + anal, peekChars, sampleStr, minLen, maxLen, groups, regexp, inregex = /*process.argv[2] || /xyz([abc0-9]){2,3}/i*/"/(?[ab\\u0012cde]+)\\x12/gi" ; echo("Testing Analyzer.VERSION = " + Analyzer.VERSION); @@ -69,22 +69,28 @@ anal = Analyzer( inregex ); peekChars = anal.peek( ); minLen = anal.minimum( ); maxLen = anal.maximum( ); -regexp = anal.compile( ); +regexp = anal.compile( {i:anal.fl.i?1:0} ); sampleStr = anal.sample( 1, 5 ); +groups = anal.groups(); for(var i=0; i<5; i++) - sampleStr[i] = {sample:sampleStr[i], match:(regexp.test(sampleStr[i]) ? 'yes' : 'no')}; +{ + var m = sampleStr[i].match(regexp); + sampleStr[i] = {sample:sampleStr[i], match:(m ? 'yes' : 'no'), groups: {}}; + for(var g in groups) + if ( groups.hasOwnProperty(g) ) + sampleStr[i].groups[g] = m[regexp.group(g)]; +} echo("Input : " + inregex.toString( )); -echo("Regular Expression : " + anal.re); +echo("Regular Expression : " + anal.input()); echo("Regular Expression Flags : " + Object.keys(anal.fl).join(',')); +echo("Regular Expression Reconstructed : " + anal.source()); echo("============================================="); echo("Regular Expression Syntax Tree : "); echo(JSON.stringify(anal.tree(true), null, 4)); echo("============================================="); -echo("Regular Expression Reconstructed Source : " + anal.src); -echo("============================================="); echo("Regular Expression (Named) Matched Groups : "); -echo(JSON.stringify(anal.grp, null, 4)); +echo(JSON.stringify(groups, null, 4)); echo("============================================="); echo("Regular Expression Peek Characters : "); echo(JSON.stringify({positive:Object.keys(peekChars.positive||{}),negative:Object.keys(peekChars.negative||{})}, null, 4));