Welcome to the IDM Forum. This forum is meant as a user-to-user support mechanism where users can share knowledge and tips for all IDM software.
Since these forums are user-to-user based, IDM does not regularly read or reply to the posts in this forum. For problem reports, suggestions, or feature requests, you must email us directly. Our trained technical support staff answers most inquiries within 30 minutes.
UltraEdit.ueReOn(); /* Let's use UE's own regexp syntax */
UltraEdit.activeDocument.findReplace.regExp = true;
UltraEdit.activeDocument.findReplace.replaceAll = false;
//Find lines like:
//D 829 allapviep1n200011900a_829 2
//We use 3 tagged expressions grouping like this (shown with [] pairs)
//[D ]829[ allapviep1n200011900a_]829[ 2 ]
var regexpFind = "%^([D][ ]^)[0-9]+^([ ]*_^)[0-9]+^([ ][0-9]*^)$";
// First go to top of document
UltraEdit.activeDocument.top();
var renumberValue = 1; /* Start value */
while ( (UltraEdit.activeDocument.findReplace.find(regexpFind)) && ! UltraEdit.activeDocument.isEof() ) {
/* now replace using tagged values ^1 ^2 ^3 */
UltraEdit.activeDocument.findReplace.replace(regexpFind,"^1"+renumberValue+"^2"+renumberValue+"^3");
renumberValue++;
}
// reposition to top after renumbering
UltraEdit.activeDocument.top();


var regexpFind = "^(string^)";
UltraEdit.activeDocument.top();
var renumberValue = 1; /* Start value */
while ( (UltraEdit.activeDocument.findReplace.find(regexpFind)) && ! UltraEdit.activeDocument.isEof() ) {
UltraEdit.activeDocument.findReplace.replace(regexpFind,"^1"+renumberValue);
renumberValue++;
}

UltraEdit.ueReOn(); /* Let's use UE's own regexp syntax */
UltraEdit.activeDocument.findReplace.regExp = true;
UltraEdit.activeDocument.findReplace.replaceAll = false;
var regexpFind = "^(string^)";
// First go to top of document
UltraEdit.activeDocument.top();
var renumberValue = 1; /* Start value */
while ( (UltraEdit.activeDocument.findReplace.find(regexpFind)) && ! UltraEdit.activeDocument.isEof() ) {
UltraEdit.activeDocument.findReplace.replace(regexpFind,"^1"+renumberValue+"#END#");
renumberValue++;
}
// reposition to top after renumbering
UltraEdit.activeDocument.top();
renumberValue--;
UltraEdit.activeDocument.findReplace.replaceAll = true;
if (renumberValue >= 100000) {
UltraEdit.activeDocument.findReplace.replace(regexpFind+"^([0-9]+^)#END#","^1^2");
UltraEdit.messageBox("The script does not fully support numbers higher than 99999 !!!","Error: Too Large Number");
} else if (renumberValue >= 10000) {
UltraEdit.activeDocument.findReplace.replace(regexpFind+"^([0-9]^)#END#","^10000^2");
UltraEdit.activeDocument.findReplace.replace(regexpFind+"^([0-9][0-9]^)#END#","^1000^2");
UltraEdit.activeDocument.findReplace.replace(regexpFind+"^([0-9][0-9][0-9]^)#END#","^100^2");
UltraEdit.activeDocument.findReplace.replace(regexpFind+"^([0-9][0-9][0-9][0-9]^)#END#","^10^2");
UltraEdit.activeDocument.findReplace.replace(regexpFind+"^([0-9][0-9][0-9][0-9][0-9]^)#END#","^1^2");
} else if (renumberValue >= 1000) {
UltraEdit.activeDocument.findReplace.replace(regexpFind+"^([0-9]^)#END#","^1000^2");
UltraEdit.activeDocument.findReplace.replace(regexpFind+"^([0-9][0-9]^)#END#","^100^2");
UltraEdit.activeDocument.findReplace.replace(regexpFind+"^([0-9][0-9][0-9]^)#END#","^10^2");
UltraEdit.activeDocument.findReplace.replace(regexpFind+"^([0-9][0-9][0-9][0-9]^)#END#","^1^2");
} else if (renumberValue >= 100) {
UltraEdit.activeDocument.findReplace.replace(regexpFind+"^([0-9]^)#END#","^100^2");
UltraEdit.activeDocument.findReplace.replace(regexpFind+"^([0-9][0-9]^)#END#","^10^2");
UltraEdit.activeDocument.findReplace.replace(regexpFind+"^([0-9][0-9][0-9]^)#END#","^1^2");
} else if (renumberValue >= 10) {
UltraEdit.activeDocument.findReplace.replace(regexpFind+"^([0-9]^)#END#","^10^2");
UltraEdit.activeDocument.findReplace.replace(regexpFind+"^([0-9][0-9]^)#END#","^1^2");
} else {
UltraEdit.activeDocument.findReplace.replace(regexpFind+"^([0-9]^)#END#","^1^2");
}





Mofi wrote:Uncheck search setting Continue find at End of File ...


if (UltraEdit.document.length > 0)
{
UltraEdit.insertMode();
UltraEdit.columnModeOff();
UltraEdit.ueReOn();
UltraEdit.activeDocument.top();
UltraEdit.activeDocument.findReplace.mode=0;
UltraEdit.activeDocument.findReplace.matchCase=true;
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 sSearchRegExp = "^(||PKNAME|FIELDLIST_ID|||PKVALUE|^)*^(||*FIELDLIST_ID^^^)*~CR";
var sReplaceRegExp = "^1STRING_VALUE_000^2STRING_VALUE_000~CR";
var sNumber = "000";
var nNumber = 0;
do
{
nNumber++;
if (nNumber >= 100) sNumber = nNumber.toString();
else if (nNumber >= 10) sNumber = "0" + nNumber.toString();
else sNumber = "00" + nNumber.toString();
sReplaceRegExp = "^1STRING_VALUE_" + sNumber + "^2STRING_VALUE_" + sNumber + "~CR";
}
while (UltraEdit.activeDocument.findReplace.replace(sSearchRegExp,sReplaceRegExp));
UltraEdit.save();
}
if (UltraEdit.document.length > 0)
{
// Define editing mode for the script.
UltraEdit.insertMode();
UltraEdit.columnModeOff();
// Use the UltraEdit regular expression engine.
UltraEdit.ueReOn();
// Set caret to top of file.
UltraEdit.activeDocument.top();
// Define the parameters for find and replace.
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;
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;
// This expression in UltraEdit syntax is for finding the hexadecimal
// values of ACQUISITIONFIELDLIST_ID or ACQUISITIONORGLIST_ID. The
// asterisk in the regular expression string makes it an OR expression.
var sSearchRegExp = "|PKNAME|ACQUISITION*_ID|||PKVALUE|[0-9A-F]+";
var sNumber = "000";
var nNumber = 0;
// Run the following loop as long as a hexadecimal value can be found.
while(UltraEdit.activeDocument.findReplace.find(sSearchRegExp))
{
nNumber++;
if (nNumber >= 100) sNumber = nNumber.toString();
else if (nNumber >= 10) sNumber = "0" + nNumber.toString();
else sNumber = "00" + nNumber.toString();
var sReplace = "\" + STRING_VALUE_" + sNumber + " + \"";
// The found string is selected. Replaced should be only all
// occurrences of the last 32 characters. It would be very easily
// possible to get just the last 32 characters from the selected
// string. But it is perhaps better to get everything after last |
// of selected string into a string variable in case the length
// of the hexadecimal value will change ever in the future.
var nLastPipePos = UltraEdit.activeDocument.selection.lastIndexOf('|');
var sFound = UltraEdit.activeDocument.selection.substr(++nLastPipePos);
// Search for the hexadecimal value and replace all occurrences
// with current string value number. Caret position in the file
// is not changed on replace all. So next find continues on first
// line where the string was just replaced.
UltraEdit.activeDocument.findReplace.replace(sFound, sReplace);
}
// Save the file when modified.
if (nNumber) UltraEdit.save();
}