zsh 匹配不包含破折号的文件

zsh match files not containing dash

我有如下文件列表:

001file.jpg
003file.jpg
001-800x600-sq.jpg
001-800x600.jpg
002-800x600-sq.jpg
002-800x600.jpg
003-800x600-sq.jpg
003-800x600.jpg
004-800x531-sq.jpg
004-800x531.jpg
005-800x531-sq.jpg
005-800x531.jpg
006-800x531-sq.jpg
006-800x531.jpg
007-800x531-sq.jpg
007-800x531.jpg
008-800x1067-sq.jpg
008-800x1067.jpg
009-800x1067-sq.jpg
009-800x1067.jpg
010-800x533-sq.jpg
010-800x533.jpg
011-800x1200-sq.jpg
011-800x1200.jpg
012-800x533-sq.jpg
012-800x533.jpg
013-800x600-sq.jpg
013-800x600.jpg
014-800x1067-sq.jpg
014-800x1067.jpg
015-800x533-sq.jpg
015-800x533.jpg
016-800x533-sq.jpg
016-800x533.jpg

在 ZSH 中,我想列出所有以任意数字开头的文件,文件名中不包含破折号,所以我尝试了:

print -l <->[^-]*.jpg

没有成功。这个模式有什么问题!?

我认为这类似于 <-> 的文档警告的情况:

Be careful when using other wildcards adjacent to patterns of this form; for example, <0-9>* will actually match any number whatsoever at the start of the string, since the `<0-9>' will match the first digit, and the `*' will match any others. This is a trap for the unwary, but is in fact an inevitable consequence of the rule that the longest possible match always succeeds. Expressions such as `<0-9>[^[:digit:]]*' can be used instead.

print -l <->[^-]*.jpg 中,<-> 匹配第一个数字,然后 [^-] 匹配第二个数字,* 匹配其他所有内容。

改用

print -l <->[^[:digit:]-]*.jpg