正则表达式可视化工具html代码

代码语言:html

所属分类:其他

代码描述:正则表达式可视化工具html代码,输入正则表达式后,可立即生成可视化图形。

代码标签: 正则 表达式 可视化 工具 html 代码

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<style>
body,html * {
margin:0;
padding:0;
font-family:sans-serif;
}
body {
background: #303030;
}
.code,.code * {
  font-family: "DejaVu Sans Mono",monospace;
}
h1 {
font-size:3em;
color:#40C0FF;
margin:14px 0;
padding:0 16px;
padding-top:40px;
padding-bottom: 20px;
border-bottom:2px dashed grey;
min-height:60px;
}
h1 em{
color:#BBE0E0;
font-size:small;
padding-left:2em;
font-style: normal;
font-weight:normal;
display:inline-block;
}
#inputCt,#errorBox {
margin:8px 16px;
}
#inputCt div.re {
background:#EEE;
font-size:1.2em;
line-height: 1.4em;
color:#333;
border:1px solid black;
padding:4px;
font-weight: bold;
word-break:break-all;
word-wrap:break-word;
}
#inputCt div.re table {
border:none;
padding:0;
margin:0;
width:100%;
}
#inputCt div.re .input {
color:#3030C0;
padding:0 2px;
border:none;
background:#EEE;
font-size:1.2em;
line-height: 1.4em;
height:1.4em;
font-weight: bold;
word-break:break-all;
word-wrap:break-word;
margin:0;
width:auto;
}
#inputCt div.re #input {
display:table;
width:100%;
}
#inputCt label {
  color:white;
  cursor:pointer;
  display:inline-block;
}
#inputCt label input {
  margin-right:4px;
}
#errorBox {
background:#EEE;
font-size:1.2em;
line-height: 1.4em;
border:1px solid black;
padding:4px;
color:darkred;
white-space: pre;
word-wrap:normal;
word-break:keep-all;
display: none;
overflow:auto;
}
#visualIt,#embedIt,#exportIt {
font-size: 16px;
line-height: 16px;
display: inline-block;
margin: 10px;
margin-left:0;
padding:12px;
padding-bottom:10px;
color:#EEF;
border:none;
cursor:pointer;
background: #40B0EF;
background-image: linear-gradient(to bottom, #40B0EF,#3060A0);
border-radius: 12px;
text-decoration: none;
}
#visualIt:hover,#embedIt:hover,#exportIt:hover {
color:#FEF;
background: #3CB0FD;
background-image: linear-gradient(to bottom, #3CB0FD, #3498DF);
text-decoration: none;
}
#graphCt {
padding:4px;
margin:0px 16px;
border:1px solid black;
background: #EEE;
overflow: auto;
cursor:move;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
#graphCt svg {
display:block;
margin:0 auto;
}
footer div.normal {
text-align: center;
border-top:1px solid grey;
margin:1em auto;
padding:10px;
font-size:1.2em;
}
footer,footer a {
color:#EEF;
}

footer div.embed {
  display: none;
}
body.embed {
  background: #EEE;
}
body.embed,body.embed #graphCt {
  margin:0;
  padding:0;
  border:none;
}
body.embed h1,
body.embed #inputCt,
body.embed #github {
  display:none !important;
}
body.embed footer div.normal {
  display:none;
}
body.embed footer div.embed {
  display: block;
}
body.embed footer div.embed,body.embed div.footer a {
  color:white;
  font-size: 14px;
}
body.embed footer {
  display:block;
  width:auto;
  margin:0;
  padding:2px 10px;
  background:rgb(75,0,130);
  opacity: 0.85;
  position:fixed;
  right:0;
  bottom:0;
}
body.embed{height:100%;}
body.embed #graphCt {
  height: 100vh;
}
.exportCanvas {
  display:block;
  margin:0 auto;
  image-rendering: pixelated;
}
</style>
</head>
<body>
<script>
var params=getParams();
if (params.embed || params.cmd=="export") {
  document.body.className+= " embed";
}

function trim(s) {
  return s.replace(/^\s+/,'').replace(/\s+$/,'');
}

function getParams() {
  var params=location.hash;
  if (!params || params.length<2) {
    params={embed:false,re:"",highlight:true,flags:''};
  } else {
    params=params.slice(2);
    params=params.split("&").reduce(function (p,a) {
      a=a.split("=");
      p[a[0]]=a[1];
      return p;
    },{});
    params.embed=params.embed==='true';
    params.flags=params.flags || '';
    params.re=params.re?trim(decodeURIComponent(params.re)):'';
  }
  return params;
}
</script>
<h1>Regulex <em>JavaScript Regular Expression Visualizer.</em></h1>
<div id="inputCt">
<div class="re code">
<table>
<tr>
<td style="width:1em">/</td>
<td style="width:auto">
<input id="input" class="input" value="^(a|b)*?$" />
</td>
<td style="width:1em">/</td>
<td style="width:3em" id="flagBox"></td>
</tr>
</table>
</div>
<button id="visualIt">Visualize</button>
<button id="exportIt">Export Image</button>
<button id="embedIt">Embed On My Site!</button>
<label><input type="checkbox" name="flag" value="i" />IgnoreCase</label>
<label><input type="checkbox" name="flag" value="m" />Multiline</label>
<label><input type="checkbox" name="flag" value="g" />GlobalMatch</label>
</div>
<p id="errorBox" class="code">Error Message</p>
<div id="graphCt" class="code"></div>
<script type="text/javascript">
var requirejs,require,define;if(function(t){function e(t,e){return v.call(t,e)}function r(t,e){var r,n,i,a,s,o,c,h,u,l,f,p=e&&e.split("/"),d=g.map,x=d&&d["*"]||{};if(t&&"."===t.charAt(0))if(e){for(p=p.slice(0,p.length-1),t=t.split("/"),s=t.length-1,g.nodeIdCompat&&m.test(t[s])&&(t[s]=t[s].replace(m,"")),t=p.concat(t),u=0;u<t.length;u+=1)if("."===(f=t[u]))t.splice(u,1),u-=1;else if(".."===f){if(1===u&&(".."===t[2]||".."===t[0]))break;u>0&&(t.splice(u-1,2),u-=2)}t=t.join("/")}else 0===t.indexOf("./")&&(t=t.substring(2));if((p||x)&&d){for(r=t.split("/"),u=r.length;u>0;u-=1){if(n=r.slice(0,u).join("/"),p)for(l=p.length;l>0;l-=1)if((i=d[p.slice(0,l).join("/")])&&(i=i[n])){a=i,o=u;break}if(a)break;!c&&x&&x[n]&&(c=x[n],h=u)}!a&&c&&(a=c,o=h),a&&(r.splice(0,o,a),t=r.join("/"))}return t}function n(e,r){return function(){var n=y.call(arguments,0);return"string"!=typeof n[0]&&1===n.length&&n.push(null),u.apply(t,n.concat([e,r]))}}function i(t){return function(e){return r(e,t)}}function a(t){return function(e){p[t]=e}}function s(r){if(e(d,r)){var n=d[r];delete d[r],x[r]=!0,h.apply(t,n)}if(!e(p,r)&&!e(x,r))throw new Error("No "+r);return p[r]}function o(t){var e,r=t?t.indexOf("!"):-1;return r>-1&&(e=t.substring(0,r),t=t.substring(r+1,t.length)),[e,t]}function c(t){return function(){return g&&g.config&&g.config[t]||{}}}var h,u,l,f,p={},d={},g={},x={},v=Object.prototype.hasOwnProperty,y=[].slice,m=/\.js$/;l=function(t,e){var n,a=o(t),c=a[0];return t=a[1],c&&(c=r(c,e),n=s(c)),c?t=n&&n.normalize?n.normalize(t,i(e)):r(t,e):(t=r(t,e),a=o(t),c=a[0],t=a[1],c&&(n=s(c))),{f:c?c+"!"+t:t,n:t,pr:c,p:n}},f={require:function(t){return n(t)},exports:function(t){var e=p[t];return void 0!==e?e:p[t]={}},module:function(t){return{id:t,uri:"",exports:p[t],config:c(t)}}},h=function(r,i,o,c){var h,u,g,v,y,m,b=[],_=typeof o;if(c=c||r,"undefined"===_||"function"===_){for(i=!i.length&&o.length?["require","exports","module"]:i,y=0;y<i.length;y+=1)if(v=l(i[y],c),"require"===(u=v.f))b[y]=f.require(r);else if("exports"===u)b[y]=f.exports(r),m=!0;else if("module"===u)h=b[y]=f.module(r);else if(e(p,u)||e(d,u)||e(x,u))b[y]=s(u);else{if(!v.p)throw new Error(r+" missing "+u);v.p.load(v.n,n(c,!0),a(u),{}),b[y]=p[u]}g=o?o.apply(p[r],b):void 0,r&&(h&&h.exports!==t&&h.exports!==p[r]?p[r]=h.exports:g===t&&m||(p[r]=g))}else r&&(p[r]=o)},requirejs=require=u=function(e,r,n,i,a){if("string"==typeof e)return f[e]?f[e](r):s(l(e,r).f);if(!e.splice){if(g=e,g.deps&&u(g.deps,g.callback),!r)return;r.splice?(e=r,r=n,n=null):e=t}return r=r||function(){},"function"==typeof n&&(n=i,i=a),i?h(t,e,r,n):setTimeout(function(){h(t,e,r,n)},4),u},u.config=function(t){return u(t)},requirejs._defined=p,define=function(t,r,n){r.splice||(n=r,r=[]),e(p,t)||e(d,t)||(d[t]=[t,r,n])},define.amd={jQuery:!0}}(),define("libs/almond",function(){}),"function"!=typeof define)var define=require("amdefine")(module);if(define("Kit",[],function(){function t(e,a){return e._Set?e:(a||(e=n(e)),e.contains=function(t,n){return!!~r(e,t,n)},e.indexOf=function(t,n){return r(e,t,n)},e.toArray=function(){return i(e)},e.union=function(r){r=t(r);for(var n=e.length+r.length,a=new e.constructor(n),s=0,o=0,c=0;c<n;c++)e[s]===r[o]?(a[c]=e[s++],o++,n--):e[s]<r[o]?a[c]=e[s++]:a[c]=r[o++];return a.length=n,t(a.length===n?a:i(a,n),!0)},e.inspect=e.toArray,e._Set=!0,e)}function e(t,e){return t<e?E:t===e?C:k}function r(t,r,n){var i,a,s=0,o=t.length,c=o-1;if(o<1)return-1;if(n=n||e,1===o)return n(r,t[s])===C?s:-1;if(n(r,t[s])===E||n(r,t[c])===k)return-1;do{if(i=s+(c-s+1>>1),(a=n(r,t[i]))===C)return i;a===E?c=i-1:s=i+1}while(s<=c);return-1}function n(t){var e=t.length;if(e<=1)return t;for(var r,n,a,s=1,o=e/3|0;s<o;)s=3*s+1;for(;s>0;){for(r=s;r<e;r++)for(n=r;n>=s&&t[n]<t[n-s];n-=s)a=t[n],t[n]=t[n-s],t[n-s]=a;s=s/3|0}var c=t[0];for(r=1,n=1;r<e;r++)t[r]!==c&&(c=t[n++]=t[r]);return t.length=n,t.length===n?t:i(t,n)}function i(t,e){e=void 0===e?t.length:e;for(var r=new t.constructor(e),n=e;n--;)r[n]=t[n];return r}function a(t){for(var e,r={},n=0,i=0,a=t.length;n<a;n++)e=t[n],r.hasOwnProperty(e)||(r[e]=1,t[i++]=e);return t.length=i,t}function s(t){var e,r,n,i=t.length,a=(1e10*Math.random()).toString(32)+(+new Date).toString(32);for(e=r=0;e<i;e++)null!=(n=t[e])&&(n.hasOwnProperty(a)||(Object.defineProperty(n,a,{value:1,enumerable:!1}),t[r++]=n));for(e=r;e--;)t[e][a]=void 0;return t.length=r,t}function o(t){t=t.map(function(t){return t[1]?t:t+t});var e,r,i,a,s,o;t=n(t),o=t.length;var c,h,u=Object.create(null),l=Object.create(null),f=Object.create(null);for(e=0;e<o;e++)for(s=t[e],h=s[1],l[s[0]]=!0,f[h]=!0,r=e;r<o;r++)if((c=t[r][0])>=h){c===h&&(u[h]=!0);break}var g=n(t.join("").split("")),x=Object.keys(u),v=g[0],y=Object.create(null),m=Object.create(null);for(e=0;e<o;e++)y[t[e]]=[];if(u[v])for(e=0;e<o;e++)if(s=t[e],s[0]===v)y[s].push(v);else if(s[0]>v)break;for(e=0,a=g.length-1;e<a;e++){if(c=g[e],h=g[e+1],f[c]&&(c=d(c)),l[h]&&(h=p(h)),c<=h)for(v=c===h?c:c+h,r=0;r<o&&(s=t[r],!(s[0]>h));r++)s[0]<=c&&h<=s[1]&&(y[s].push(v),x.push(v));if(c=g[e],h=g[e+1],u[h])for(r=0;r<o&&(s=t[r],!(s[0]>h));r++)s[0]<=h&&h<=s[1]&&y[s].push(h)}x=n(x);for(i in y)m[i[0]===i[1]?i[0]:i]=y[i];return{ranges:x,map:m}}function c(t){var e=String.fromCharCode(65535);t=o(t).ranges;var r=[];if(!t.length)return r;"\0"!==t[0][0]&&t.unshift(e);var n=t.length-1;return(t[n][1]||t[n][0])!==e&&t.push("\0"),t.reduce(function(t,e){var n=d(t[1]||t[0]),i=p(e[0]);return n<i&&r.push(n+i),n===i&&r.push(n),e}),r}function h(t){t=t.split("");var e=[],r=[],n="^"===t[0]&&t.length>1&&t.shift();return t.forEach(function(t){if("-"==e[0]&&e.length>1){if(e[1]>t)throw new Error("Charset range out of order:"+e[1]+"-"+t+"!");r.push(e[1]+t),e.splice(0,2)}else e.unshift(t)}),r=r.concat(e),n?c(r):o(r).ranges}function u(t){if(!t.length)return[];var e=[t[0]];return t.reduce(function(t,r){var n=e.length-1;return t[t.length-1]===p(r[0])?e[n]=e[n][0]+r[r.length-1]:(e.push(r),r)}),e.reduce(function(t,e){return 2===e.length&&e[0]===p(e[1])?(t.push(e[0]),t.push(e[1])):t.push(e),t},[])}function l(t){return String.fromCharCode(t)}function f(t){return t.charCodeAt(0)}function p(t){return String.fromCharCode(t.charCodeAt(0)-1)}function d(t){return String.fromCharCode(t.charCodeAt(0)+1)}function g(t,e){var r=/[\x00-\x1F\x7F-\x9F]/,n=/[\u009F-\uFFFF]/;return t=t.split("").map(function(t){return!e&&S.hasOwnProperty(t)?S[t]:n.test(t)?"\\u"+("00"+f(t).toString(16).toUpperCase()).slice(-4):r.test(t)?"\\x"+("0"+f(t).toString(16).toUpperCase()).slice(-2):t}).join("")}function x(t){return[].concat.apply([],t)}function v(t,e){return new Array(e+1).join(t)}function y(){var t=_.call(arguments);if(w)Function.prototype.apply.apply(console.log,[console,t]);else{var e=require("util");t.forEach(function(t){console.log(e.inspect(t,{showHidden:!1,customInspect:!0,depth:64,colors:!0}))})}}function m(t){for(var e,r=t.toString(),n=/^\s+function\s+([a-zA-Z]\w+)\s*\(/gm,i=[];e=n.exec(r);)i.push(e[1]);for(var t,a=[];t=i.pop();)a.push(t+":"+t);return"{\n"+a.join(",\n")+"\n}"}var b=Array.prototype,_=b.slice,w=function(){return"[object Window]"===this.toString()}(),E=-1,C=0,k=1,S={"\n":"\\n","\t":"\\t","\f":"\\f","\r":"\\r"," ":" ","\\":"\\\\","\0":"\\0"};return{sortUnique:n,idUnique:s,hashUnique:a,Set:t,repeats:v,negate:c,coalesce:u,classify:o,parseCharset:h,chr:l,ord:f,pred:p,succ:d,toPrint:g,flatten2:x,log:y,isBrowser:w,locals:m}}),"function"!=typeof define)var define=require("amdefine")(module);if(define("NFA",["./Kit"],function(t){function e(e){e=e.compact?c(e):e;var s,o={},h=e.trans,u={};for(s=0,n=e.accepts.length;s<n;s++)o[e.accepts[s]]=!0;var l;for(s=0,n=h.length;s<n;s++)l=h[s],l.charset?l.ranges="string"==typeof l.charset?t.parseCharset(l.charset):l.charset:l.eMove=!0,l.from.forEach(function(t){var e=u[t]=u[t]||{eMoveStates:[],eMove:[],charMove:{},trans:[],ranges:[]};l.eMove?e.eMoveStates=e.eMoveStates.concat(l.to):e.ranges=e.ranges.concat(l.ranges),e.trans.push(l)});return Object.keys(u).forEach(function(e){var r=u[e],n=r.trans,i=r.charMove,a=r.eMove,s=r.ranges,o=t.classify(s),c=o.map;n.forEach(function(e){e.eMove?e.to.forEach(function(t){a.push({to:t,action:e.action,assert:e.assert,eMove:!0})}):t.flatten2(e.ranges.map(function(t){return c[t]})).forEach(function(t){(i[t]=i[t]||[]).push(e)})}),s=t.Set(o.ranges.filter(function(t){return!!t[1]})),r.ranges=s,Object.keys(i).forEach(function(t){var e=i[t],r=[];n.forEach(function(t){t.to.forEach(function(n){(t.eMove||~e.indexOf(t))&&r.push({to:n,action:t.action,assert:t.assert,eMove:t.eMove})})}),i[t]=r}),delete r.trans,delete r.eMoveStates}),{accepts:o,router:u,input:a,assertDFA:i,accept:r}}function r(t){return this.accepts.hasOwnProperty(t)}function i(){for(var e,r=this.router,n=Object.keys(r),i=0,a=n.length;i<a;i++){if(e=r[n[i]],e.eMove.length>1)throw new Error("DFA Assertion Fail!\nFrom state `"+n[i]+"` can goto to multi ε-move states!");for(var s=e.charMove,o=Object.keys(s),c=0,h=o.length;c<h;c++){if(1!==s[o[c]].length)throw t.log(s),new Error("DFA Assertion Fail!\nFrom state `"+n[i]+"` via charset `"+o[c]+"` can goto to multi states!")}if(o.length&&e.eMove.length)throw new Error("DFA Assertion Fail!\nFrom state `"+n[i]+"` can goto extra ε-move state!")}return!0}function a(e,r,n){function i(e,r,o,c,h){t:for(;;){var u,l,f,p,d=a.router[o];if(!d)break;var g,x=d.eMove,v=d.charMove;r<e.length?(u=e[r],g=v.hasOwnProperty(u)?v[u]:(l=s(d.ranges,u))?v[l]:x):g=x;for(var y,m,b,_=c.length,w=h,E=0,C=g.length;E<C;E++){if(y=g[E],f=y.eMove?0:1,h=w,c.splice(0,c.length-_),_=c.length,y.assert){if(!1===(m=y.assert(c,u,r,o,e)))continue;"number"==typeof m&&(r+=m,h+=m)}if(y.action&&(c=y.action(c,u,r,o,e)||c),h=y.eMove?h:r,n&&t.log(u+":"+o+">"+y.to),E===C-1){r+=f,o=y.to;continue t}if(b=i(e,r+f,y.to,c,h),b.acceptable)return b;p=b}if(p)return p;break}return{stack:c,lastIndex:h,lastState:o,acceptable:a.accept(o)}}r=r||0;var a=this;return i(e,r,"start",[],r-1)}function s(t,e){var r=t.indexOf(e,o);return!!~r&&t[r]}function o(t,e){var r=e[0];return t>e[1]?1:t<r?-1:0}function c(t){t.accepts=t.accepts.split(",");for(var e,r,n,i,a=t.trans,s=a.length;s--;)e=a[s],r=e[0].split(">"),n=r[0].split(","),i=r[1].split(","),a[s]={from:n,to:i,charset:e[1],action:e[2],assert:e[3]};return t.compact=!1,t}return e}),"function"!=typeof define)var define=require("amdefine")(module);if(define("parse",["./NFA","./Kit"],function(t,e){function r(){var t=Object.keys(p).map(function(t){return t+"="+JSON.stringify(p[t])}).join(";");(function(){return this})().eval(t)}function n(t){this.raw=t.raw,this.tree=t.tree,this.groupCount=t.groupCount}function i(t,e){d=e;var r,i,s,p=a();r=p.input(t,0,e),i=r.stack,i=v.endChoice(i),s=r.lastState;var g=r.acceptable&&r.lastIndex===t.length-1;if(!g){var x;switch(s){case"charsetRangeEndWithNullChar":x={type:"CharsetRangeEndWithNullChar",message:"Charset range end with NUL char does not make sense!\nBecause [a-\\0] is not a valid range.\nAnd [\\0-\\0] should be rewritten into [\\0]."};break;case"repeatErrorFinal":x={type:"NothingRepeat",message:"Nothing to repeat!"};break;case"digitFollowNullError":x={type:"DigitFollowNullError",message:"The '\\0' represents the <NUL> char and cannot be followed by a decimal digit!"};break;case"charsetRangeEndClass":x={type:"CharsetRangeEndClass",message:'Charset range ends with class such as "\\w\\W\\d\\D\\s\\S" is invalid!'};break;case"charsetOctEscape":x={type:"DecimalEscape",message:"Decimal escape appears in charset is invalid.Because it can't be explained as  backreference.And octal escape is deprecated!"};break;default:0===s.indexOf("charset")?x={type:"UnclosedCharset",message:"Unterminated character class!"}:")"===t[r.lastIndex]?x={type:"UnmatchedParen",message:"Unmatched end parenthesis!"}:(x={type:"UnexpectedChar",message:"Unexpected char!"},r.lastIndex++)}if(x)throw x.lastIndex=r.lastIndex,x.astStack=r.stack,x.lastState=s,new f(x)}if(i._parentGroup)throw new f({type:"UnterminatedGroup",message:"Unterminated group!",lastIndex:i._parentGroup.indices[0],lastState:s,astStack:i});if(g){var y=i.groupCounter?i.groupCounter.i:0;delete i.groupCounter,h(i,t,t.length),i=o(i);var m=new n({raw:t,groupCount:y,tree:i});return m.traverse(l,CHARSET_NODE),m.traverse(u,ASSERT_NODE),c(i),d=!1,m}}function a(){return g||(g=t(E,d)),g}function s(t,e,r){Object.defineProperty(t,e,{value:r,enumerable:d,writable:!0,configurable:!0})}function o(t){return t.filter(function(t){return t.type==EXACT_NODE&&t.concatTemp?(delete t.concatTemp,!!t.chars):(t.sub?t.sub=o(t.sub):t.branches&&(t.branches=t.branches.map(o)),!0)})}function c(t){function e(t){t.sub?c(t.sub):t.branches&&t.branches.map(c)}var r=t[0];e(r);for(var n,i=1,a=1,s=t.length;i<s;i++){if(n=t[i],n.type===EXACT_NODE){if(r.type===EXACT_NODE&&!r.repeat&&!n.repeat){r.indices[1]=n.indices[1],r.raw+=n.raw,r.chars+=n.chars;continue}}else e(n);t[a++]=n,r=n}r&&(t.length=a)}function h(t,e,r){if(!t.length)return void t.push({type:EMPTY_NODE,indices:[r,r]});t.reduce(function(t,r){return r.indices.push(t),r.raw=e.slice(r.indices[0],t),r.type===GROUP_NODE||r.type===ASSERT_NODE&&r.sub?h(r.sub,e,r.endParenIndex):r.type===CHOICE_NODE?(r.branches.reduce(function(t,r){h(r,e,t);var n=r[0];return(n?n.indices[0]:t)-1},t),r.branches.reverse()):r.type===EXACT_NODE&&(r.concatTemp||(r.chars=r.chars||r.raw)),r.indices[0]},r),t.reverse()}function u(t){if(t.repeat){var e=t.assertionType,r="Nothing to repeat! Repeat after assertion doesn't make sense!";if("AssertLookahead"===e||"AssertNegativeLookahead"===e){var n="AssertLookahead"===e?"?=":"?!",i="("+n+"b)";r+="\n/a"+i+"+/、/a"+i+"{1,n}/ are the same as /a"+i+"/。\n/a"+i+"*/、/a"+i+"{0,n}/、/a"+i+"?/ are the same as /a/。"}throw new f({type:"NothingRepeat",lastIndex:t.indices[1]-1,message:r})}}function l(t){t.ranges=e.sortUnique(t.ranges.map(function(t){if(t[0]>t[1])throw new f({type:"OutOfOrder",lastIndex:t.lastIndex,message:"Range ["+t.join("-")+"] out of order in character class!"});return t.join("")}))}function f(t){this.name="RegexSyntaxError",this.type=t.type,this.lastIndex=t.lastIndex,this.lastState=t.lastState,this.astStack=t.astStack,this.message=t.message,Object.defineProperty(this,"stack",{value:new Error(t.message).stack,enumerable:!1})}var p={EXACT_NODE:"exact",CHARSET_NODE:"charset",CHOICE_NODE:"choice",GROUP_NODE:"group",ASSERT_NODE:"assert",DOT_NODE:"dot",BACKREF_NODE:"backref",EMPTY_NODE:"empty",AssertLookahead:"AssertLookahead",AssertNegativeLookahead:"AssertNegativeLookahead",AssertNonWordBoundary:"AssertNonWordBoundary",AssertWordBoundary:"AssertWordBoundary",AssertEnd:"AssertEnd",AssertBegin:"AssertBegin"};r(),n.prototype.traverse=function(t,e){function r(t,n){t.forEach(function(t){e&&t.type!==e||n(t),t.sub?r(t.sub,n):t.branches&&t.branches.forEach(function(t){r(t,n)})})}r(this.tree,t)};var d;i.Constants=p,i.exportConstants=r,i.RegexSyntaxError=f,i.getNFAParser=a;var g;f.prototype.toString=function(){return this.name+" "+this.type+":"+this.message};var x={n:"\n",r:"\r",t:"\t",v:"\v",f:"\f"},v=function(){function t(t,e,r){var n=t[0];(!n||n.type!=EXACT_NODE||n.repeat||n.chars&&!n.concatTemp)&&t.unshift({type:EXACT_NODE,indices:[r]}),n&&n.concatTemp&&(n.chars+=e)}function e(t,e,r){t.unshift({type:DOT_NODE,indices:[r]})}function r(t,e,r){t.unshift({type:EXACT_NODE,chars:"\0",indices:[r-1]})}function n(t,e,r){t.unshift({type:ASSERT_NODE,indices:[r],assertionType:AssertBegin})}function i(t,e,r,n,i){t.unshift({type:ASSERT_NODE,indices:[r],assertionType:AssertEnd})}function a(t,e,r){t.unshift({type:ASSERT_NODE,indices:[r-1],assertionType:"b"==e?AssertWordBoundary:AssertNonWordBoundary})}function o(t,e,r){t[0].type!==EXACT_NODE&&t.unshift({type:EXACT_NODE,indices:[r]})}function c(t,e,r){s(t[0],"_commaIndex",r)}function h(t,e,r,n,i){var a,s=t[0],o=i.lastIndexOf("{",r),c=parseInt(i.slice(o+1,s._commaIndex||r),10);if(s._commaIndex){if((a=s._commaIndex+1==r?1/0:parseInt(i.slice(s._commaIndex+1,r),10))<c)throw new f({type:"OutOfOrder",lastState:n,lastIndex:r,astStack:t,message:"Numbers out of order in {} quantifier!"});delete s._commaIndex}else a=c;s.indices[0]>=o&&t.shift(),d(t,c,a,o,i)}function u(t,e,r,n,i){d(t,0,1/0,r,i)}function l(t,e,r,n,i){d(t,0,1,r,i)}function p(t,e,r,n,i){d(t,1,1/0,r,i)}function d(t,e,r,n,i){var a=t[0],o={min:e,max:r,nonGreedy:!1},c=n-1;if(a.chars&&1===a.chars.length&&(c=a.indices[0]),a.type===EXACT_NODE){var h={type:EXACT_NODE,repeat:o,chars:a.chars?a.chars:i[c],indices:[c]};a.indices[0]===c&&t.shift(),t.unshift(h)}else a.repeat=o;s(o,"beginIndex",n-t[0].indices[0])}function g(t){t[0].repeat.nonGreedy=!0}function v(t,e,r){t.unshift({concatTemp:!0,type:EXACT_NODE,chars:"",indices:[r]})}function y(t,e,r){x.hasOwnProperty(e)&&(e=x[e]),t.unshift({type:EXACT_NODE,chars:e,indices:[r-1]})}function m(t,e,r){t.unshift({type:CHARSET_NODE,indices:[r-1],chars:"",ranges:[],classes:[e],exclude:!1})}function b(t,e,r,n,i){e=String.fromCharCode(parseInt(i[r-1]+e,16)),t.shift(),t.unshift({type:EXACT_NODE,chars:e,indices:[r-3]})}function _(t,e,r,n,i){e=String.fromCharCode(parseInt(i.slice(r-3,r+1),16)),t.shift(),t.unshift({type:EXACT_NODE,chars:e,indices:[r-5]})}function w(t,e,r){var n=t.groupCounter=t.groupCounter||{i:0};n.i++;var i={type:GROUP_NODE,num:n.i,sub:[],indices:[r],_parentStack:t};return t=i.sub,s(t,"_parentGroup",i),t.groupCounter=n,t}function E(t){var e=t._parentGroup;e.nonCapture=!0,e.num=void 0,t.groupCounter.i--}function C(t,e,r){var n=t._parentGroup;n.type=ASSERT_NODE,n.assertionType="="==e?AssertLookahead:AssertNegativeLookahead,n.num=void 0,t.groupCounter.i--}function k(t,e,r,n,i){t=A(t);var a=t._parentGroup;if(!a)throw new f({type:"UnexpectedChar",lastIndex:r,lastState:n,astStack:t,message:"Unexpected end parenthesis!"});return delete t._parentGroup,delete t.groupCounter,t=a._parentStack,delete a._parentStack,t.unshift(a),a.endParenIndex=r,t}function S(t,e,r){var n,i=[];if(t._parentChoice)n=t._parentChoice,n.branches.unshift(i),s(i,"_parentChoice",n),s(i,"_parentGroup",n),i.groupCounter=t.groupCounter,delete t._parentChoice,delete t.groupCounter;else{var a=t[t.length-1];n={type:CHOICE_NODE,indices:[a?a.indices[0]:r-1],branches:[]},s(n,"_parentStack",t),n.branches.unshift(t.slice()),t.length=0,t.unshift(n),i.groupCounter=t.groupCounter,s(i,"_parentChoice",n),s(i,"_parentGroup",n),n.branches.unshift(i)}return i}function A(t){if(t._parentChoice){var e=t._parentChoice;delete t._parentChoice,delete t._parentGroup,delete t.groupCounter;var r=e._parentStack;return delete e._parentStack,r}return t}function B(t,e,r){t.unshift({type:CHARSET_NODE,indices:[r],classes:[],ranges:[],chars:""})}function N(t){t[0].exclude=!0}function O(t,e,r){t[0].chars+=e}function T(t,e,r){x.hasOwnProperty(e)&&(e=x[e]),t[0].chars+=e}function R(t,e,r){t[0].chars+="\0"}function I(t,e){t[0].classes.push(e)}function M(t,e,r,n,i){var a=t[0];e=String.fromCharCode(parseInt(a.chars.slice(-1)+e,16)),a.chars=a.chars.slice(0,-2),a.chars+=e}function F(t,e,r,n,i){var a=t[0];e=String.fromCharCode(parseInt(a.chars.slice(-3)+e,16)),a.chars=a.chars.slice(0,-4),a.chars+=e}function D(t,e,r,n,i){var a=t[0],s=a.chars.slice(-2);s=[s[0],e],s.lastIndex=r,a.ranges.push(s),a.chars=a.chars.slice(0,-2)}function P(t,e){x.hasOwnProperty(e)&&(e=x[e]),D.apply(this,arguments)}function L(t,e,r){var n=t[0],i=n.chars.slice(-3)+e;n.chars=n.chars.slice(0,-3);var a=n.ranges.pop();e=String.fromCharCode(parseInt(i,16)),a=[a[0],e],a.lastIndex=r,n.ranges.push(a)}function z(t,e,r){var n=t[0],i=n.chars.slice(-1)+e;n.chars=n.chars.slice(0,-1);var a=n.ranges.pop();e=String.fromCharCode(parseInt(i,16)),a=[a[0],e],a.lastIndex=r,n.ranges.push(a)}function j(t,e,r,n){function i(t,e){return!!e._parentGroup&&(e._parentGroup.num==t?t:i(t,e._parentGroup._parentStack))}var a=t[0],s=parseInt(e,10),o="escape"===n,c=t.groupCounter,h=c&&c.i||0;if(o?(a={type:BACKREF_NODE,indices:[r-1]},t.unshift(a)):s=parseInt(a.num+""+s,10),s>h)throw new f({type:"InvalidBackReference",lastIndex:r,astStack:t,lastState:n,message:"Back reference number("+s+") greater than current groups count("+h+")."});if(i(s,t))throw new f({type:"InvalidBackReference",lastIndex:r,astStack:t,lastState:n,message:"Recursive back reference in group ("+s+") itself."});a.num=s}return{escapeStart:v,exact:t,dot:e,nullChar:r,assertBegin:n,assertEnd:i,assertWordBoundary:a,repeatnStart:o,repeatnComma:c,repeatNonGreedy:g,repeatnEnd:h,repeat1:p,repeat01:l,repeat0:u,charClassEscape:m,normalEscape:y,unicodeEscape:_,hexEscape:b,charClassEscape:m,groupStart:w,groupNonCapture:E,backref:j,groupToAssertion:C,groupEnd:k,choice:S,endChoice:A,charsetStart:B,charsetExclude:N,charsetContent:O,charsetNullChar:R,charsetClassEscape:I,charsetHexEscape:M,charsetUnicodeEscape:F,charsetRangeEnd:D,charsetNormalEscape:T,charsetRangeEndNormalEscape:P,charsetRangeEndUnicodeEscap.........完整代码请登录后点击上方下载按钮下载查看

网友评论0