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

Re: file globbing



> On 05 August 2021 at 16:27 Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx> wrote:
> > On 05 August 2021 at 16:14 Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
> > Say I have these files:
> > 
> >       0 [2021-08-05--07:58] d,1
> >       0 [2021-08-05--07:59] d,1,first
> >       0 [2021-08-05--07:59] d,1,second
> > 
> > I want a glob that captures them all but:
> > 
> >      $ print -l d,1[^[:digit:]]*(N)
> >      d,1,first
> >      d,1,second
> 
> Yes, indeed it looks like this is available by default (you don't even need EXTENDED_GLOB).
> 
> d,1([^[:digit:]]*|)(N)
> 
> The (either_this|or_that) matches either what you originally said or nothing ("or_that" here is empty).
> 
> There are other ways of doing it, and there's a ksh/bash-compatible way, too, but that's probably
> the one I'd immediately reach for.

Actually, come to think of it, I can't resist mention one other one, since it keeps the squiggles
to a bare minimum, though this *does* require "setopt extendedglob".

d,1^[[:digit:]]*

That means "d,1" following by anything that doesn't match the pattern after the "^".  Caution
needs to be exercised with more complicated uses of "^", though --- negative match assertions
can be really counterintuitive.

pws




Messages sorted by: Reverse Date, Date, Thread, Author