From 8176ef315181dc38e41e80c6509d591bddf86db1 Mon Sep 17 00:00:00 2001 From: Sebastian Gniazdowski Date: Thu, 26 Dec 2019 19:22:41 +0100 Subject: [PATCH] Extend description of S flag --- Doc/Zsh/expn.yo | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Doc/Zsh/expn.yo b/Doc/Zsh/expn.yo index d7147dbd7..36813dc20 100644 --- a/Doc/Zsh/expn.yo +++ b/Doc/Zsh/expn.yo @@ -1399,6 +1399,19 @@ from the beginning and with tt(%) start from the end of the string. With substitution via tt(${)...tt(/)...tt(}) or tt(${)...tt(//)...tt(}), specifies non-greedy matching, i.e. that the shortest instead of the longest match should be replaced. +The substring search means that the pattern is matched skipping the +parts of the input string starting from the direction set by the use +of tt(#) or tt(%). For example, to match a pattern starting from the +end, one could use: + +example(str="abcXXXdefXXXghi" +out=${(S)str%%(#b)([^X])X##(*)} +out=$out$match[1]$match[2]) + +The result is tt(abcXXXdefghi). It would have been tt(abcXXXdefXXghi) +if the substitution would have been tt(${(S)str%%X##}), as despite the +tt(%%) specifies a greedy match, the substring matching works by +trying matches from right to left and stops at a first valid match. ) item(tt(I:)var(expr)tt(:))( Search the var(expr)th match (where var(expr) evaluates to a number). -- 2.21.0