zsh-users
 help / color / mirror / code / Atom feed
* End Index number not what I expected
@ 2016-12-06 17:09 Jim
  2016-12-06 20:16 ` Peter Stephenson
       [not found] ` <20161206201629.2970ef18__5617.78782071105$1481055469$gmane$org@ntlworld.com>
  0 siblings, 2 replies; 3+ messages in thread
From: Jim @ 2016-12-06 17:09 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 1458 bytes --]

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-12-10 14:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-06 17:09 End Index number not what I expected Jim
2016-12-06 20:16 ` Peter Stephenson
     [not found] ` <20161206201629.2970ef18__5617.78782071105$1481055469$gmane$org@ntlworld.com>
2016-12-10 14:56   ` Daniel Shahaf

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).