I want to create a glob expression that recognises filenames that don't have any full stops (periods) in them, and use that expression within Ruby code. I realise that ordinary glob expressions can't do this. However, bash extglob has a syntax that can handle this. Is it possible to use a bash extglob style pattern in Ruby, either using core Ruby libraries, or third party gems?
I tried using File::FNM_EXTGLOB
, but that didn't work. The following is a simplified scenario to test whether File::FNM_EXTGLOB
has the exact same syntax as bash extglob, and it seems not to be the case:
File.fnmatch("myfile_+[0-9].txt", "myfile_123.txt", File::FNM_EXTGLOB)
Also, the English-language and Japanese-language documentation of File.fnmatch
only talk about File::FNM_EXTGLOB
allowing you to use a union of two possibilities such as File.fnmatch('c{at,ub}s', 'cats', File::FNM_EXTGLOB)
.
Alternatives to using a glob expression would be to go to regular expressions, or possibly using the operating system to do the globbing itself, but I'd rather not go down those paths if possible.
The documentation that you linked to describes everything that can be done with FNM_EXTGLOB
in Ruby; that is, the braces are the only extra functionality that you get while using that flag. Not sure if there are any external libraries but I doubt that there are.