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

Re: Example of use of (S) flag



On Dec 23, 11:25pm, Stephane Chazelas wrote:
} Subject: Re: Example of use of (S) flag
}
} 2015-12-23 19:25:05 +0100, Sebastian Gniazdowski:
} > Hello,
} > completion says that (S) is "search substrings in #, %, /
} > expressions". Can someone provide example of (S) influence? Thanks
} [...]
} 
} $ a=ababa
} $ echo ${(S)a#b}
} aaba
} $ echo ${(S)a%b}
} abaa

Note also that ${(S)var:#pat} is not useful; pat must still match the
entire value of $var (or an element of $var in the array case) for the
element to be matched/removed.

Further note that (MS) is sort of a dumbed-down form of backreferences,
returning something similar to the value of $MATCH in an extendeglob
pattern that uses (#m) (except extendedglob is not needed).  E.g.:

% a=abcba
% echo ${(MS)a#b?}
bc
% echo ${(MS)a%b?}
ba

Here are some examples of the use with ${var/pat/repl}:

torch% echo ${a/b*/x}    
ax
torch% echo ${(S)a/b*/x}
axcba
torch% echo ${(S)a//b*/x}
axcxa



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