In this case it would be 27+3+2+2+1=35 which is pretty simple to add up. But I have various files with from 250 to 3700 lines and would like to be able to get totals from them.
The common thing is target='sub_results'>number from 1 to 5000 time and there is not more than one occurrence of the string per line.
The following script should work. I tested it on your example with UE v18.00.0.1034. It is not clear for me if there is one file containing all the results or if you want to get the results from a set of files. The script expects that the lines with the results are in active file on script execution. You may need first to run a Find in Files with Results to Edit Window if you first need to get all lines with results from a set of files.
if (UltraEdit.document.length > 0) { // Is at least 1 file opened?
// Define environment for the script.
UltraEdit.insertMode();
if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();
else if (typeof(UltraEdit.activeDocument.columnModeOff) == "function") UltraEdit.activeDocument.columnModeOff();
// Move caret to top of active file.
UltraEdit.activeDocument.top();
// Define the parameters for the case-sensitive Perl regular
// expression Find command used to find the numbers to sum.
UltraEdit.perlReOn();
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;
// Initialize the 2 number variables for the sum and the counter for found results.
var nSum = 0;
var nCount = 0;
// Run from top of file to bottom a case-sensitive Perl regular expression
// Find searching for numbers after fixed string "target='sub_results'>"
// using a lookbehind to select just the found number by the Find command.
while (UltraEdit.activeDocument.findReplace.find("(?<=target='sub_results'>)\\d+")) {
// Convert the found number string to an integer number and add it to existing sum.
nSum += parseInt(UltraEdit.activeDocument.selection,10);
nCount++; // Increase the counter by 1 on every found results number.
}
// Display the user of the script the sum with a message box.
UltraEdit.messageBox("Sum of " + nCount + " results is " + nSum);
}