Globbing - What am I doing wrong?

I am using Crystal 1.10.1.

I have directory containing the file a.0 and I try the following:

Dir.glob("*.[0-9]") #=> ["a.0"]
Dir.glob("?.[0-9]") #=> ["a.0"]
Dir.glob("a.[0-9]") #=> []

What’s going on with that last glob?

I guess this is a bug, because same code when run with Ruby, it works!

# Ruby code

p Dir.glob("a.[0-9]")
# => ["a.0"]
1 Like
1 Like

There are many possible workarounds in the meantime. Here’s one using regex:

p Dir.glob("*").select { |f| f =~ /^a\.\d$/ }
# => ["a.0"]