Re: alternation option end of string

Ray Andrews <[email protected]> Fri, 1 May 2026 21:44:58 -0700
Newsgroups gmane.comp.shells.zsh.devel,gmane.comp.shells.zsh.user
Message-ID <[email protected]>
On 2026-05-01 17:44, Eric Cook wrote:
> So, bart guessed correct, you are using pattern matching.
> string=cats; print -- ${(M)string##cat(s|)}
I wonder if I have my terminology correct -- I thought Bart was 
suggesting that I was matching filenames -- globbing, yes?  But it was 
me who said that, no, I'm doing pattern matching.  The strings are in 
fact filenames, but in the current situation they're just strings, 
there's no completion of lists of files so I'm not calling that globbing.
>
> tho, in this particular case, you could just do: ${(M)string##cats#}
>
I wonder if I have some option incorrect.  Extendedglob in ON:

% string=cat; out=${(M)string##cat(s|)}; echo $out
cat GOOD

% string=catz; out=${(M)string##cat(s|)}; echo $out
cat BAD

% string=cats; out=${(M)string##cat(s|)}; echo $out
cats GOOD

% string=cats; out=${(M)string##cats#}; echo $out
cats GOOD

% string=cat; out=${(M)string##cats#}; echo $out
cat GOOD

% string=catz; out=${(M)string##cats#}; echo $out
cat BAD

% string=catsz; out=${(M)string##cats#}; echo $out
cats GOOD

I want 'cat' to print but only if it has nothing following it except 's' 
in which case  'cats' will print irrespective of following characters. 
So 'cat' and 'cats' are the only outputs and
'catz' will print nothing but 'catszzzzz' will print 'cats'.  At the 
moment I'm doing this with two sequential tests and it works fine, but 
I'm wondering if they can be combined.