I was not aware of the htm page (it only appears in the help (which I don't read)).
It actually belongs to an older package which is now retired, but I have tried this slightly updated test:
Code: Select all
clauses
%== search
run() :-
Pattern = @"([a-zA]{2}|0) \1",
Str = "this is a line a aa aaa",
if regEx::search(Pattern, Str, Pos, Len) then
stdio::writef("Found Pos = %d, len = %d.\n", Pos, Len)
% Found Pos = 2, len = 5.
end if,
fail. %fail to next clause.
run() :-
Pattern = @"([a-zA]{2}|0) \1",
Str = "this is a line a aa aaa",
if regEx::search(Pattern, Str, false, 3, 25, Pos, Len) then
stdio::writef("Found Pos = %d, len = %d.\n", Pos, Len)
% Found Pos = 17, len = 5.
end if,
fail. %fail to next clause.
%== replace
run() :-
Pattern = @"([a-zA]{2}|0) \1",
PatternRepl = @"\nat(not \1) will be \2(it was '\0)",
Str = "this is a line a aa aaa",
if ReplaceResult = regEx::search_and_replace(Pattern, Str, false, 0, 25, PatternRepl, Pos, Len) then
stdio::writef("Found at Pos = %d, len = %d.\n", Pos, Len),
% Found Pos = 2, len = 5.
stdio::writef("Replace with: %\n", ReplaceResult)
% Replace with:
% at(not is) will be (it was 'is is').
% --Note: \1='is'; \2='' because not defined; \0='is is'
end if.
And I get this output:
Found Pos = 2, len = 5.
Found Pos = 17, len = 5.
Found at Pos = 2, len = 5.
Replace with:
at(not is) will be (it was '
All the examples are somewhat strange especially the replace example. In time we may come up with some better examples. But in any case I do not get the behavior you describe all of them gives the expected length. Do notice that it is a length not an end-position.