Let us look together on data
to evaluate by Perl regular expression find string
The Perl regular expression search finds first id="
and starts now the evaluation of the OR expression (in a capturing group, non capturing group would be a little bit faster here).
The first 6 characters of toc-cha
pter match with the data in the line, but 7th character is not matching. So the first argument of the OR expression does not result in a positive match.
The Perl regular expression find function traces back to character after id="
and evaluates now the second argument toc-ch
which indeed results in a 100% match. So second argument of OR expression is positive and as there is no more criteria for a positive match of entire search string after the OR expression, the task is done with finding id="toc-ch
which is selected and caret is blinking after this string in the file.
The next regular expression find should match everything from current position in file to "
which is in this case just the character 1. So the script does what you coded, but what you don't want.
Here is an improved code for your task to get the string of interest into a string variable. It uses a lookbehind and a lookahead to match just intro
in right context, i.e. with id="toc-
before and "
as next character.
Code: Select all
var nSec = UltraEdit.activeDocument.selection;
Some more hints:
The line var nSec = UltraEdit.activeDocument.copy(UltraEdit.clipboardContent);
is nonsense in your code.
The function UltraEdit.activeDocument.copy()
does not take any parameter. This function copies always the selected text in active document to active clipboard. So UltraEdit.clipboardContent
is completely ignored. The value returned to variable nSec
is the boolean value true
which does not mean that the copy was successful. The returned value is always true
even if nothing was copied as nothing selected in active file. The property UltraEdit.clipboardContent
(string member variable of UltraEdit object/class) has no effect here at all.
To copy a string to active clipboard and assign the clipboard content later to a string variable the could would be:
Code: Select all
var sClipboardText = UltraEdit.clipboardContent;
The variable name nSec
looks like based on my naming convention, but used wrong. The prefix n
means in my naming convention that the variable Sec
holds a number (integer value), but in code above it holds a string and should be named sSec
according to my naming convention. See this post