Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: array filtering
- X-seq: zsh-users 30015
- From: Ray Andrews <rayandrews@xxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: array filtering
- Date: Sun, 9 Jun 2024 15:15:19 -0700
- Archived-at: <https://zsh.org/users/30015>
- In-reply-to: <CAEnqoMCNfAYnvioeP=rJsDCcwoXEeyHqcvn10mR5BWWX+j=KAA@mail.gmail.com>
- List-id: <zsh-users.zsh.org>
- References: <f142a706-2a5a-4065-ae47-674b0d873f1f@eastlink.ca> <CAEnqoMCNfAYnvioeP=rJsDCcwoXEeyHqcvn10mR5BWWX+j=KAA@mail.gmail.com>
On 2024-06-09 13:27, Rick Bowen wrote:
Try this? Works for any value of $1
except when 1=""
arr=( ${(M)arr%%*/[^/]#${1}[^/]#/} )
First look, that seems to be about what Lawrence is saying. Thanks
Rick.
Lawrence:
> arr=(${(M)arr:#(#i)*/[^/]#$1[!/]#/})
> Sorry, I used both "[^/]" and "[!/]" out of absentmindedness, not
for any technically necessary reason. They do the same thing.
Good to know. The bang is more intuitive.
> No. These are shell patterns, not regular expressions. "[^/]*"
matches one non-"/" character followed by zero or more arbitrary
characters.
There's regex, there's globbing and then there's shell patterns. It's not easy to keep them in separate drawers in my mind. It's one of those things that one learns better by instruction than by T&E.
> Since you're using EXTENDED_GLOB (something you always neglect to
mention), you can use "[^/]#" to match zero or more non-slashes.
I have yet to start playing with those options so I don't think about it. For me EXTENDED_GLOB is like gravity, it's just there and I don't consider turning it off. One of the non-existent docs I dream about would be a deep dive into the options from a practical viewpoint. I only know what a fraction of them do.
Thanks both.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author