Re: alternation option end of string

Bart Schaefer <[email protected]>
Newsgroups gmane.comp.shells.zsh.devel
Message-ID <CAH+w=7a=-a8GXm_8uGyqUN0bCirR48GFe_fGfXSTTG037eYrVg__24119.5396449015$1777683278$gmane$org@mail.gmail.com>
On Fri, May 1, 2026 at 5:44 PM Eric Cook <[email protected]> wrote:
>
> On 5/1/26 8:36 PM, Ray Andrews wrote:
> >
> > On 2026-05-01 16:56, Ray Andrews wrote:
> >
> > I must be doing something wrong:
> >
> > % string='cats'
> >
> > % out="${(M)string##cat(s|$)}"; echo $out
> > cats
> >
> > % string='cat'
> >
> > % out=${(M)string##cat(s|$)}; echo $out
> >
> > [nothing]
>
> So, bart guessed correct, you are using pattern matching.
> string=cats; print -- ${(M)string##cat(s|)}
>
> tho, in this particular case, you could just do:  ${(M)string##cats#}

s# requires extendedglob to be set, (s|) does not.

There are some edge cases where (s|) vs. (|s) produce different
results, but you're unlikely to run into them.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.