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

Re: End Index number not what I expected



On Tue, 6 Dec 2016 11:09:39 -0600
Jim <linux.tech.guy@xxxxxxxxx> wrote:
> 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?

No.

There's a test in the test suite...

  # This (1) doesn't work with // or /
  #      (2) perhaps ought to be 18, to be consistent with normal zsh
  #          substring indexing and with backreferences.
  print ${(BES)string##white}
0:${(BE...)...}
>14 19

I think this is just an underused feature that's been allowed to get
away with it.  It should at least be properly documented, though it
would be preferable if it was more consistent.

pws

diff --git a/Doc/Zsh/expn.yo b/Doc/Zsh/expn.yo
index 87ca790..cf4f69e 100644
--- a/Doc/Zsh/expn.yo
+++ b/Doc/Zsh/expn.yo
@@ -1394,7 +1394,8 @@ item(tt(B))(
 Include the index of the beginning of the match in the result.
 )
 item(tt(E))(
-Include the index of the end of the match in the result.
+Include the index one character past the end of the match in the result
+(note this is inconsistent with other uses of parameter index).
 )
 item(tt(M))(
 Include the matched portion in the result.



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