Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
array filtering
- X-seq: zsh-users 30011
- From: Ray Andrews <rayandrews@xxxxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: array filtering
- Date: Sun, 9 Jun 2024 10:49:30 -0700
- Archived-at: <https://zsh.org/users/30011>
- List-id: <zsh-users.zsh.org>
I'm getting better at various filterings
but this one eludes me:
arr=( /dira/${1}/dirb/ /dirc/A${1}B/dird/ /dire/${1}/
/dirf/C${1}D/ )
... it's pretty fussy, but I want to filter out the first and
second elements. The test is that for a list of directories, for
an element to be retained the argument ($1) may be an exact
directory name, or a partial directory name, but it must be the
last directory. Not sure if I'm expressing that correctly. No
subdirectories may follow the matched name, be it exact or
partial.
arr=( ${(M)arr:#(#i)*/$1/} )
... that works if the name matches exactly but:
arr=( ${(M)arr:#(#i)*/*$1*/} )
... that ends up too broad, $1 matches anywhere irrespective of
slashes.
arr=( ${(M)arr:#(#i)*/*$1[^/]*/} )
... ends up too narrow, it catches a completed name but misses the
exact match which puzzles me because I'd read that: '... anything
except a slash, any number of characters or none' -- which should
find the exact match: ' [^/]* ' should simply be empty, no?
Messages sorted by:
Reverse Date,
Date,
Thread,
Author