Re: alternation option end of string

Eric Cook <[email protected]>
Newsgroups gmane.comp.shells.zsh.devel
Message-ID <0357522b-3917-4be2-b969-2b1a7481115c__43807.0544785418$1777682737$gmane$org@gmx.com>
On 5/1/26 8:36 PM, Ray Andrews wrote:
> 
> 
> On 2026-05-01 16:56, Ray Andrews wrote:
>>
>>
>> On 2026-05-01 15:39, Mark J. Reed wrote:
>>> $
>>>
>>> e.g. 'a(b|$)' will match an a that is either followed by a b or at the end of the strings
>>>
>>>
> 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#}
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.