Scroll down to “Filename Generation”, and enable either
extended_glob (which should be the default, but isn't for backward compatibility) or
ksh_glob. Both zsh's extended globs and ksh's have the full power of regular expressions.
ERE syntax ksh glob zsh extended glob
(foo)* *(foo) (foo)#
(foo)+ +(foo) (foo)##
(foo)? ?(foo) (|foo)
(foo|bar) @(foo|bar) (foo|bar)
Keep in mind that most tools that use regular expressions use them as search patterns that must match a substring, but globs are always used as patterns that must match the whole string. For example
foofoobar does not match the zsh glob
(foo)##, since after
foofoo there's some text left over.
Zsh has additional operators that don't extend the expressive power but make some expressions easier to write. The operators
ksh_glob) provide negation, e.g.
!(foo) matches anything except
foo, which in regex syntax requires the unwieldy
|[^f].*|f[^o].*|fo[^o].*. The operator
<…-…> (zsh-specific, does not require
extended_glob) matches any integer (in decimal notation) in a range, e.g.
10 but not
So, excluding issues like unprintable characters,
ls | grep -e "ABC[0-9]\+" can be written in ways such as
print -lr -- *ABC[0-9]##*(N) # requires extended_glob
print -lr -- *ABC+([0-9])*(N) # requires ksh_glob
print -lr -- *ABC+<->(N)
But since “one or more digit then anything” is equivalent to “a digit then anything”, it can also be written
print -lr -- *ABC[0-9]*(N)