Regex numeric range generator

Hi everyone,

I use Glob.jl to load multiple files, and I had a problem when I needed to distinguish filename by numeric range (files were saved with datetime in filename). The problem can be solved by using a regex numeric range generator (I found this answer on Stack Overflow: regex - a regular expression generator for number ranges - Stack Overflow). I am wondering if this could be implemented in Julia, and have decided to raise this discussion on discourse instead of GitHub.

Also, this is my first post so I’m not sure if this should be tagged here or in First Steps.

Can’t you just parse the numbers/dates from the filenames, and filter on them?

An MWE, or at least a list of filenames, would be useful.

Thanks! Indeed, I can just use a filter post pattern matching instead of messing with the pattern matching.
For the sake of future viewers, I’ll include a MWE.

Filenames are in the format subject_date_time.filetype :

...
CON10_190605_112630.rhs
CON10_190605_133411.rhs
CON10_190605_154209.rhs
CON10_190605_172930.rhs
...

Code to get files from 190605_12000 (noon) to 190605_160000 (4pm)

using Glob
files = glob("../data/CON10_190605_*.rhs")
times = [split(split(filename, "_")[end], ".")[1] for filename in files]
filtered_files = files[(times .> "12000") .& (times .< "160000")]

So regarding the discussion topic, I guess it’s simple enough for the user to implement and there is no need for any package to include this (regex numeric range generator)?

Dunno. That’s for package authors to decide. I would say that given access to a generic programing language like Julia, regexs are the wrong tool to match numeric ranges.

2 Likes