javascript - UltraEdit find and replace regular expression -


i have code bellow find regular expression after %hostname , replaces text correrctly #hostname.

how replicate %location , #location. can't seem replication working more 1 variable.

thanks

var host= "%hostname =(.*)"; // perl regular expression find title string             ultraedit.activedocument.top();                                                         // turn on regular expressions                                                         ultraedit.activedocument.findreplace.regexp = true;                                    // find                                                                             ultraedit.activedocument.findreplace.find(host);                                        // load selection                                                            var host2= ultraedit.activedocument.selection;                                          // javascript function 'match' match regex within javascript engine       // can extract actual title via array                                        t = host2.match(host);                                                                 savehost = t[1];                                                                       ultraedit.activedocument.top();                                                        ultraedit.activedocument.findreplace.replaceall=true;                                 ultraedit.activedocument.findreplace.matchcase=true;                                  ultraedit.activedocument.findreplace.replace("#hostname", savehost); 

here ultraedit script task.

the array asvariables contains names of variables can extended additional strings.

if (ultraedit.document.length > 0)  // file opened? {    // define environment script.    ultraedit.insertmode();    ultraedit.columnmodeoff();     // define constant array of variable names can extended    // or modified in script code @ time support more variables.    var asvariables = [ "hostname" , "location" ];     // define once find , replace options make    // script independent on internal defaults of ultraedit.    ultraedit.perlreon();    ultraedit.activedocument.findreplace.mode=0;    ultraedit.activedocument.findreplace.matchcase=true;    ultraedit.activedocument.findreplace.matchword=false;    ultraedit.activedocument.findreplace.searchdown=true;    if (typeof(ultraedit.activedocument.findreplace.searchincolumn) == "boolean")    {       ultraedit.activedocument.findreplace.searchincolumn=false;    }    ultraedit.activedocument.findreplace.preservecase=false;    ultraedit.activedocument.findreplace.replaceall=true;    ultraedit.activedocument.findreplace.replaceinallopen=false;     // run code in loop on variables defined in array.    (var nvariable = 0; nvariable < asvariables.length; nvariable++)    {       // move caret top of active file.       ultraedit.activedocument.top();        // perl regular expression find %variable string , assigned data.       var ssearch = "%" + asvariables[nvariable] + " *?=.*$";        ultraedit.activedocument.findreplace.regexp=true;        // if variable not found in active file,       // continue next variable.       if(!ultraedit.activedocument.findreplace.find(ssearch)) continue;        // string after first equal sign selected string.       // replace method of javascript string object never modifies       // string value itself. creates new string derived       // current string value replace applied.       var sdata = ultraedit.activedocument.selection.replace(/^.*?=(.*)$/,"$1");        // replace occurrences of #variable found data in entire file.       ultraedit.activedocument.top();       ultraedit.activedocument.findreplace.regexp=false;       ssearch = "#" + asvariables[nvariable];       ultraedit.activedocument.findreplace.replace(ssearch,sdata);    } } 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -