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

Re: array filtering




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