Your task can be done with following script using UltraEdit regular expression engine.
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.ueReOn();
UltraEdit.activeDocument.top();
UltraEdit.activeDocument.findReplace.mode=0;
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=false;
UltraEdit.activeDocument.findReplace.replaceInAllOpen=false;
var nNumber = 0;
var sReplace = "";
do {
nNumber++;
sReplace = nNumber.toString() + ". ";
} while (UltraEdit.activeDocument.findReplace.replace("%[0-9]+. ",sReplace));
}
The code below should do the same using Perl regular expression engine, but results in UE v18.00.0.1025 in incrementing in an endless loop the first occurrence of a number. That is definitely a bug in UE v18.00.0.1025 which I will report to IDM support by email.
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.perlReOn();
UltraEdit.activeDocument.top();
UltraEdit.activeDocument.findReplace.mode=0;
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=false;
UltraEdit.activeDocument.findReplace.replaceInAllOpen=false;
var nNumber = 0;
var sReplace = "";
do {
nNumber++;
sReplace = nNumber.toString() + ". ";
} while (UltraEdit.activeDocument.findReplace.replace("^[0-9]+\\. ",sReplace));
}
Update 1: The script above with the Perl regular expression results in an endless loop since v14.00 of UltraEdit. In UE v13.20 the script works as is. In UE v13.00 and v13.10 the numbers are found, but not replaced. The reason for the endless loop with UE v14.00 and later is the fact that a replaced string is still selected after replace when using the Perl regular expression engine while there is no selection anymore when doing a non regular expression, UE regular expression or Unix regular expression replace. This different behavior on selection after replace can be seen also with making the replace manually with Perl regular expression enabled.
Another possible solution for UE v17.20 and later using Perl is:
Code: Select all
do {
nNumber++;
sReplace = nNumber.toString() + ". ";
UltraEdit.activeDocument.cancelSelect();
} while (UltraEdit.activeDocument.findReplace.replace("^[0-9]+\\. ",sReplace));
For UE v14.00 to v17.10 not supporting
cancelSelect() following can be used with Perl:
Code: Select all
do {
nNumber++;
sReplace = nNumber.toString() + ". ";
UltraEdit.activeDocument.findReplace.replace("^[0-9]+\\. ",sReplace);
UltraEdit.activeDocument.key("RIGHT ARROW");
} while (UltraEdit.activeDocument.isFound());
And the last solution working for all versions of UltraEdit since v13.00, the first version of UE supporting scripts, using Perl:
Code: Select all
var nNumber = 1;
while (UltraEdit.activeDocument.findReplace.find("^[0-9]+\\. ")) {
UltraEdit.activeDocument.write(nNumber + ". ");
nNumber++;
}
Update 2: With UE v19.00 and UES v13.00 the text replaced by a Perl regular expression replace is no longer selected and therefore the script works without a workaround code for discarding the selection.