I have a *.txt file containing multiple regex pattern line by line, for example:
I'm trying to create a script which will go through each line of the regex pattern and find if there is a (or multiple) match found in one or more of the *.xml files in the user defined directory and basically shortlist them to a new file, i.e. if for example <copyright-statement>[~&] and <caption><p>^(*^)</p></caption> do not not match anything in the files then the output file should contain:
Below is the script code I'm currently using:
But the script has some issues:
Code: Select all
aff id="[a-z]+
<author-footnotes>^p<sup>[0-9]+-[a-z]+</sup>
<copyright-statement>[~&]
<label>^p^p</label>
<caption><p>^(*^)</p></caption>
-graphic-[0-9]+[a-z]
Code: Select all
aff id="[a-z]+
<author-footnotes>^p<sup>[0-9]+-[a-z]+</sup>
<label>^p^p</label>
-graphic-[0-9]+[a-z]
Code: Select all
if (UltraEdit.document.length > 0)
{
UltraEdit.insertMode();
if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();
else if (typeof(UltraEdit.activeDocument.columnModeOff) == "function") UltraEdit.activeDocument.columnModeOff();
UltraEdit.activeDocument.hexOff();
UltraEdit.activeDocument.selectAll();
if (UltraEdit.activeDocument.isSel())
{
var asLines = UltraEdit.activeDocument.selection.split("\r\n");
UltraEdit.activeDocument.top();
var sDirectory = UltraEdit.getString("Enter full directory path:",1);
if (sDirectory[sDirectory.length-1] != '\\') sDirectory += '\\';
UltraEdit.frInFiles.filesToSearch=0;
UltraEdit.ueReOn();
UltraEdit.frInFiles.directoryStart=sDirectory;
UltraEdit.frInFiles.searchInFilesTypes="*.xml";
UltraEdit.frInFiles.useEncoding=false;
UltraEdit.frInFiles.ignoreHiddenSubs=true;
UltraEdit.frInFiles.matchCase=false;
UltraEdit.frInFiles.reverseSearch=false;
UltraEdit.frInFiles.matchWord=false;
UltraEdit.frInFiles.openMatchingFiles=false;
UltraEdit.frInFiles.displayLinesDoNotMatch=false;
UltraEdit.frInFiles.useOutputWindow=false;
UltraEdit.frInFiles.searchSubs=true;
UltraEdit.frInFiles.regExp=true;
for (var nLineNum = 0; nLineNum < asLines.length; nLineNum++)
{
if (!asLines[nLineNum].length) continue;
UltraEdit.frInFiles.find(asLines[nLineNum]);
}
UltraEdit.activeDocument.top();
UltraEdit.insertMode();
if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();
else if (typeof(UltraEdit.activeDocument.columnModeOff) == "function") UltraEdit.activeDocument.columnModeOff();
UltraEdit.activeDocument.hexOff();
UltraEdit.ueReOn();
UltraEdit.activeDocument.findReplace.matchCase=false;
UltraEdit.activeDocument.findReplace.matchWord=false;
UltraEdit.activeDocument.findReplace.regExp=true;
UltraEdit.activeDocument.findReplace.searchDown=true;
UltraEdit.activeDocument.findReplace.searchInColumn=false;
UltraEdit.activeDocument.findReplace.preserveCase=false;
UltraEdit.activeDocument.findReplace.replaceAll=true;
UltraEdit.activeDocument.findReplace.replaceInAllOpen=false;
UltraEdit.activeDocument.findReplace.replace("----------------------------------------", "");
UltraEdit.activeDocument.findReplace.replace("%[~F]*$", "");
UltraEdit.activeDocument.findReplace.replace("Found '", "");
UltraEdit.activeDocument.findReplace.replace("' * time(s).", "");
UltraEdit.activeDocument.findReplace.replace("%[^t ]++[^r^n]+", "");
UltraEdit.activeDocument.sortAsc(0,false,true,1,-1);
}
}
- I want the new output file to show matched patterns identical to the first file, i.e. <label>^p^p</label> should be written into the new file as <label>^p^p</label> on one line.
- The scripts takes too much time to operate. Can it be made more efficient?
- I've approximately 100 patterns to search for and some of them are using Perl regex. Is it possible to tell the script that from line 1 to say line 60 use UltraEdit regex and use Perl regex from line 61 to end? If possible, how?