I also upgraded my own online editor and added regular expression search and replacement function to it

Time:2021-1-23

I also upgraded my own online editor and added regular expression search and replacement function to it

Of course, the search and replace function can choose not to select regular expressions.

Two key functions (it took three hours for the test to succeed), it’s time to come! Check “regular?” After that, you can search content across lines.

function find(isdesc){
  var startPos=Editor.selectionStart,endPos=Editor.selectionEnd;
  var isreg=document.se.isreg.checked;
  var str=document.se.find.value;
  if(str=='')return false;
  var tmpStr=Editor.value,len=str.length,ss=-1;
  if(tmpStr=='')return false;
  //console.log(startPos+','+endPos+','+tmpStr.length);
  if(!isdesc){
  if(startPos==tmpStr.length)startPos=Editor.selectionStart=endPos=Editor.selectionEnd=0;
  if(isreg){
  var reg=new RegExp(str,"im");
  tmpStr=tmpStr.substr(endPos);
  var arr=tmpStr.match(reg);
  if(arr){str=arr[0];len=str.length;ss=tmpStr.indexOf(str)+endPos;}
  }
  else{
  ss=tmpStr.indexOf(str,endPos);
  }
  if(ss>-1){ Editor.selectionStart=ss ; Editor.selectionEnd=ss +Len;} else {alert ('bottom found '); Editor.selectionStart=Editor .selectionEnd=0;}
  }
  else{
  if(endPos==0)startPos=Editor.selectionStart=endPos=Editor.selectionEnd=tmpStr.length;
  if(isreg){
  var reg=new RegExp(str,"img");
  tmpStr=tmpStr.substring(0,startPos);
  var arr=tmpStr.match(reg);
  if(arr){
  str=arr[arr.length-1];
  len=str.length;
  ss=tmpStr.lastIndexOf(str);
  }
  }
  else{
  ss=tmpStr.lastIndexOf(str,startPos-len);
  }
  if(ss>-1){ Editor.selectionStart=ss ; Editor.selectionEnd=ss +Len;} else {alert ('top found '); Editor.selectionStart=Editor .selectionEnd= tmpStr.length ;}
  }
}
function replace(isall){
    var str=document.se.find.value,str2=document.se.for.value;
    var isreg=document.se.isreg.checked;
    if(str=='')return false;
    var tmpStr=Editor.value,len=str.length,ss=-1;
    if(tmpStr=='')return false;
    if(isall){
      var pattern=str;
    if(!isreg)pattern=str.replace(/([\/\|\.\\\(\)\*\?\^$])/g,'\\\');
        Editor.value=tmpStr.replace(new RegExp(pattern,"igm"),str2);
        //I: case insensitive, G: global search, M: multiline search
        Editor.selectionStart=Editor.selectionEnd=0;
        }
    else{
        var startPos=Editor.selectionStart,endPos=Editor.selectionEnd;
        if(isreg){
        var reg=new RegExp(str,"im");
    tmpStr=tmpStr.substr(startPos);
    var arr=tmpStr.match(reg);
    if(arr){str=arr[0];len=str.length;ss=tmpStr.indexOf(str)+startPos;str2=str.replace(reg,str2);}
        }
        else ss=tmpStr.indexOf(str,startPos);
          if(ss>-1){
          tmpStr=Editor.value;
            Editor.value=tmpStr.substring(0,ss)+str2+tmpStr.substr(ss+str.length);
            Editor.selectionStart=ss ; Editor.selectionEnd=ss +STR2. Length;} else {alert ('bottom searched '); Editor.selectionStart=Editor .selectionEnd=0;
            }
        }
    }

Now I’m translating the W3C draft of svg2.0.