一个在Flash里面使用的正则表达式的类

2008-04-02 11:03:26来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折


  一个在Flash里面使用的正则表达式的类,使用这个类的原因是FLASH里面对文本输入检测需要不高,例如就不能检测输入的邮件格式是否正确;

  
classRegExp{

  publicvarconst:String=null;

  publicvarsource:String=null;

  publicvarglobal:Boolean=false;

  publicvarignoreCase:Boolean=false;

  publicvarmultiline:Boolean=false;

  publicvarlastIndex:Number=null;

  publicstaticvar_xrStatic:Number=null;

  publicvar_xr:Number=null;

  publicstaticvar_xp:Number=null;

  publicstaticvar_xxa:Array=null;

  publicstaticvar_xxlp:Number=null;

  publicvar_xq:Number=null;

  publicvar_xqc:Number=null;

  publicstaticvard:Number=null;

  publicstaticvar_xiStatic:Number=null;

  publicvar_xi:Number=0;

  publicstaticvar_xxlm:String=null;

  publicstaticvar_xxlc:String=null;

  publicstaticvar_xxrc:String=null;

  publicstaticvarlastMatch:String=null;

  publicstaticvarleftContext:String=null;

  publicstaticvarrightContext:String=null;

  publicstaticvar_xa:Array=newArray();

  publicstaticvarlastParen:String=null;

  publicstaticvar_xaStatic:Array=newArray();

  publicstaticvar$1:String=null;

  publicstaticvar$2:String=null;

  publicstaticvar$3:String=null;

  publicstaticvar$4:String=null;

  publicstaticvar$5:String=null;

  publicstaticvar$6:String=null;

  publicstaticvar$7:String=null;

  publicstaticvar$8:String=null;

  publicstaticvar$9:String=null;

  privatestaticvar_setString:Boolean=RegExp.setStringMethods();

  functionRegExp(){

  if(arguments[0]==null){

  }else{

  const="RegExp";

  compile.apply(this,arguments);

  }

  }

  publicfunctioninvStr(sVal:String):String{

  vars=sVal;

  varl=length(s);

  varj;

  varc;

  varr="";

  for(vari=1;i<255;i ){

  c=chr(i);

  j=0;

  while(j<=l&&substring(s,1 j ,1)!=c){

  }

  if(j>l){

  r =c;

  }

  }

  returns;

  }

  publicfunctioncompile(){

  this.source=arguments[0];

  if(arguments.length>1){

  varflags=(arguments[1] ’’).toLowerCase();

  for(vari=0;i<length(flags);i ){

  if(substring(flags,i 1,1)=="g"){

  this.global=true;

  }

  if(substring(flags,i 1,1)=="i"){

  this.ignoreCase=true;

  }

  if(substring(flags,i 1,1)=="m"){

  this.multiline=true;

  }

  }

  }

  if(arguments.length<3){

  varroot=true;

  RegExp._xrStatic=1;

  //Parencounter

  vari=0;

  }else{

  varroot=false;

  this._xr=RegExp._xrStatic ;

  vari=arguments[2];

  }

  this.lastIndex=0;

  /*

  Compiletheregularexpression

  Thearrayofcharacterdefinitionobjectswillbecreated:

  q[n].t-->typeofmatchrequired:0=exact

  1=incharset

  2=notincharset

  3=paren

  4=reftoparen

  7=new"OR"section

  9=beginningofline

  10=endofline

  q[n].s-->characterorcharacterset

  q[n].a-->characterhastorepeatatleastatimes

  q[n].b-->characterhastorepeatatmostbtimes

  */

  varre=this.source;

  varex;

  varl=length(re);

  varq=[];

  varqc=0;

  vars;

  varrange=false;

  varca;

  varcb;

  varatEnd=false;

  varchar;

  for(i=i;i<l; i){

  varthischar=substring(re,i 1,1);

  if(thischar=="\\"){

  i ;

  char=false;

  thischar=substring(re,i 1,1);

  }else{

  char=true;

  }

  varnextchar=substring(re,i 2,1);

  q[qc]=newObject();

  q[qc].t=0;

  q[qc].a=0;

  q[qc].b=999;

  q[qc].c=-10;

  if(char){

  //Handlespecialcharacters

  if(thischar=="("){

  //Openingparen

  ex=newRegExp(re,(this.ignoreCase?"gi":"g"),i 1);

  i=RegExp._xiStatic;

  q[qc].t=3;

  thischar=ex;

  nextchar=substring(re,i 2,1);

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇: Flash绘画教程:麻麻原绘里依的贴网秘籍

下一篇: ActionScript入门学习-MovieClip的控制