zsh-users
 help / color / mirror / code / Atom feed
* (r) flag on scalar
@ 2015-03-08 23:38 Han Pingtian
  2015-03-09  2:56 ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Han Pingtian @ 2015-03-08 23:38 UTC (permalink / raw)
  To: zsh-user

I think below command line should give result "bc", but:

localhost% s=abcdefg
localhost% print $s[(r)bc]
b
localhost%

Looks like this isn't intuitional.


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

* Re: (r) flag on scalar
  2015-03-08 23:38 (r) flag on scalar Han Pingtian
@ 2015-03-09  2:56 ` Bart Schaefer
  2015-03-09  9:08   ` Peter Stephenson
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2015-03-09  2:56 UTC (permalink / raw)
  To: zsh-user

On Mar 9,  7:38am, Han Pingtian wrote:
} Subject: (r) flag on scalar
}
} I think below command line should give result "bc", but:
} 
} localhost% s=abcdefg
} localhost% print $s[(r)bc]
} b
} localhost%
} 
} Looks like this isn't intuitional.

$s[(r)bc] is a single index, so it's the index where the first match for
"bc" begins.

$s[(r)bc,(r)ef] is a range of indices, so it begins where "bc" begins and
ends where "ef" ends.

The only thing not quite intuitive about this is that a wildcard (either
* or with extendedglob ?# ) at the end of the ending patterrn is not
considered part of the match for (r) but is part of the match for (R).
PWS's latest doc tweak still doesn't explicitly describe that.


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

* Re: (r) flag on scalar
  2015-03-09  2:56 ` Bart Schaefer
@ 2015-03-09  9:08   ` Peter Stephenson
  2015-03-09 18:45     ` Mikael Magnusson
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 2015-03-09  9:08 UTC (permalink / raw)
  To: zsh-user

On Sun, 8 Mar 2015 19:56:42 -0700
Bart Schaefer <schaefer@brasslantern.com> wrote:
> The only thing not quite intuitive about this is that a wildcard (either
> * or with extendedglob ?# ) at the end of the ending patterrn is not
> considered part of the match for (r) but is part of the match for (R).
> PWS's latest doc tweak still doesn't explicitly describe that.

diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo
index 7b127bc..1b175b2 100644
--- a/Doc/Zsh/params.yo
+++ b/Doc/Zsh/params.yo
@@ -197,7 +197,17 @@ example(string="abcdefghijklm"
 print ${string[+LPAR()r+RPAR()d?,+LPAR()r+RPAR()h?]})
 
 prints `tt(defghi)'.  This is an obvious generalisation of the
-rule for single-character matches.
+rule for single-character matches.  For a single subscript,
+only a single character is referenced (not the range of chracters
+covered by the match).
+
+Note that in substring operations the second subscript is handled
+differently by the tt(r) and tt(R) subscript flags: the former takes the
+shortest match as the length and the latter the longest match.  Hence
+in the former case a tt(*) at the end is redundant while in
+the latter case it matches the whole remainder of the string.  This
+does not affect the result of the single subscript case as here the
+length of the match is irrelevant.
 
 subsect(Array Element Assignment)
 


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

* Re: (r) flag on scalar
  2015-03-09  9:08   ` Peter Stephenson
@ 2015-03-09 18:45     ` Mikael Magnusson
  0 siblings, 0 replies; 4+ messages in thread
From: Mikael Magnusson @ 2015-03-09 18:45 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: zsh-user

On Mon, Mar 9, 2015 at 10:08 AM, Peter Stephenson
<p.stephenson@samsung.com> wrote:
> On Sun, 8 Mar 2015 19:56:42 -0700
> Bart Schaefer <schaefer@brasslantern.com> wrote:
>> The only thing not quite intuitive about this is that a wildcard (either
>> * or with extendedglob ?# ) at the end of the ending patterrn is not
>> considered part of the match for (r) but is part of the match for (R).
>> PWS's latest doc tweak still doesn't explicitly describe that.
>
> diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo
> index 7b127bc..1b175b2 100644
> --- a/Doc/Zsh/params.yo
> +++ b/Doc/Zsh/params.yo
> @@ -197,7 +197,17 @@ example(string="abcdefghijklm"
>  print ${string[+LPAR()r+RPAR()d?,+LPAR()r+RPAR()h?]})
>
>  prints `tt(defghi)'.  This is an obvious generalisation of the
> -rule for single-character matches.
> +rule for single-character matches.  For a single subscript,
> +only a single character is referenced (not the range of chracters

characters*

-- 
Mikael Magnusson


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

end of thread, other threads:[~2015-03-09 18:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-08 23:38 (r) flag on scalar Han Pingtian
2015-03-09  2:56 ` Bart Schaefer
2015-03-09  9:08   ` Peter Stephenson
2015-03-09 18:45     ` Mikael Magnusson

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).