Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

End Index number not what I expected



Hello List,

zsh version: 5.2

So far, searches on the web have not returned a satisfactory
answer.  If I missed the answer, shame on me and sorry for
wasting you time.

The script I'm working on globs a bunch of file names then
uses portions of the file names.  As with most things in
UNIX/Linux there are multiple ways of doing things, zsh is no
exception. While trying different approaches to the task I ran
into an index issue I don't understand. Using the parameter
expansion flags (SB) and (SE) to find the beginning and end
of a match I was surprised when the ending index returned the
end of the match + 1.

The man page states:

 B   Include the index of the beginning of the match in the result.
 E   Include the index of the end of the match in the result.

Logic to me would be, if the B flag returns the index of the first
character of the match, then the E flag should return the index
of the last character of the match, not +1.

Am I missing something here?

Alternately using the conditional expression
"string =~ regexp", the integer parameters MBEGIN and MEND
work as expected.

Also in researching this I found an example of using the E flag.
The example uses a variable with a string of 10 characters,
yet using the (SE) flags the match returned an index of 11.

Should a returned index be larger the the length of the variable?

Again, just trying to understand what I'm missing here.

Thanks in advance for your help.

Sincerely,

Jim


Messages sorted by: Reverse Date, Date, Thread, Author