Hi friends,
I have a XML file with lots of tags like these
My entire script is below, how to modify it to do what I need?
Thanks for any suggestions.
I have a XML file with lots of tags like these
My goal is to find the numbers highlighted in red in the above code and increment them with a given (same for all) value, let's say 10. So the desired result is<dataLink readWrite="R/W" attribute="value" tag="CurrentRecipe.CurrentSelectedSet.82.Value" class="RecipeMgrWgt" widgetType="Project" sourceType="Recipe" dataSource="_RecipeMgr"/>
<dataLink readWrite="R/W" attribute="value" tag="CurrentRecipe.CurrentSelectedSet.157.Value" class="RecipeMgrWgt" widgetType="Project" sourceType="Recipe" dataSource="_RecipeMgr">
For this I use a javascript with a regex that is supposed to capture the number in a backreference, then I want to increment it and put it back in the place of the captured number. However this doesn't seem to work - the number is correctly captured, but always treated as a string. The result I get is either original number replaced with NaN, or replaced with a concatenated string - 10+82 looks like 1082, not as 92.<dataLink readWrite="R/W" attribute="value" tag="CurrentRecipe.CurrentSelectedSet.92.Value" class=...>
<dataLink readWrite="R/W" attribute="value" tag="CurrentRecipe.CurrentSelectedSet.167.Value" class=...>
My entire script is below, how to modify it to do what I need?
Thanks for any suggestions.
Code: Select all
if (UltraEdit.document.length > 0) // Is any file currently opened?
{
UltraEdit.insertMode(); // Define environment for the script.
UltraEdit.columnModeOff();
UltraEdit.activeDocument.top();
UltraEdit.perlReOn(); // Define the parameters for the replace.
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;
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;
// Every backslash in a JavaScript string must be escaped with a backslash to
// pass the find string correct to the UE/UES Perl regular expression engine.
var s1 = 'tag="CurrentRecipe.CurrentSelectedSet.';
var s2 = '.Value';
var offst = 10;
UltraEdit.activeDocument.findReplace.replace(
'tag="CurrentRecipe\\.CurrentSelectedSet\\.(\\d{1,3}?)\\.Value',
s1 + (offst + Number('\\1')) + s2
);
}