Look on first endnote string which should be found by your expressions:
!<a NAME="endnote_1"><p><a HREF="fvg_hbhm_text1.html#BACK_1">[1]</a>endnote endnote endnote>>
Now take a look on expression
[ !$A-Z0-9._%+-]+. What about the characters
"#[]/<>= which also exist all in the string to find but are missing in the character set definition in the expression?
The second expression is better, but does not work well because the expression does not include line terminating characters and is greedy. What you need is:
UltraEdit.activeDocument.findReplace.replace("(?s)!<a NAME=\"endnote.+?>>","XXXX");
For an explanation of
(?s) see
"." in Perl regular expressions doesn't include CRLFs?
The expressions
.+ is by default a greedy expression. That means it matches as much as possible. So it does not stop on first occurrence of
>> after string
!<a NAME="endnote, it stops left to last occurrence of
>> which is not what you want as this would result in selecting multiple endnotes with everything between. With
.+? the expression becomes non greedy and now matching any character stops left to first occurrence of
>>.
A string found with command UltraEdit.activeDocument.findReplace.find() is automatically also selected. You have 3 choices to run a string collecting loop.
Version 1: Using a user clipboard and command Copy & Append.
Code: Select all
// Use user clipboard 9 instead of Windows clipboard.
// This version should be used if Unicode characters are matched too.
UltraEdit.selectClipboard(9);
UltraEdit.clearClipboard();
UltraEdit.activeDocument.top();
while(UltraEdit.activeDocument.findReplace.find("...whatever...")) {
UltraEdit.activeDocument.copyAppend();
UltraEdit.clipboardContent += "\r\n";
}
UltraEdit.activeDocument.bottom();
UltraEdit.activeDocument.paste();
UltraEdit.clearClipboard();
UltraEdit.selectClipboard(0);
Version 2: Using a user clipboard and directly append a found string.
The second version is the same as above with the difference that instead of
UltraEdit.activeDocument.copyAppend(); the following code is used:
Code: Select all
UltraEdit.clipboardContent += UltraEdit.activeDocument.selection;
This is not working for Unicode strings. Therefore there is just a disadvantage and no advantage in comparison to first version. I have posted this version just for completness.
Version 3: Collecting found strings in a dynamic Javascript string variable.
Code: Select all
var sFoundStrings = "";
UltraEdit.activeDocument.top();
while(UltraEdit.activeDocument.findReplace.find("...whatever...")) {
sFoundStrings += UltraEdit.activeDocument.selection;
sFoundStrings += "\r\n";
}
UltraEdit.activeDocument.write(sFoundStrings);
This version does not work for Unicode strings. And as I found out once without knowing the reason this method is much slower than using the first version with using the clipboard for large files.
Please note that if the Find is a Perl regular expression find you might need as last command within while loop
UltraEdit.activeDocument.cancelSelect(); to avoid an endless loop finding last occurrence again and again.
With UE or Unix regular expressions finds or with a non regular expression find this command is not needed.
BTW: Your HTML code is invalid. You have block element <p> embedded in inline element <a>.