# Regex numeric range generator

**URL:** https://discourse.julialang.org/t/regex-numeric-range-generator/43472
**Category:** Data
**Tags:** regex
**Created:** [July 22, 2020, 4:59am UTC](https://discourse.julialang.org/t/regex-numeric-range-generator/43472 "2020-07-22T04:59:10Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![zhaoquanzheng](https://avatars.discourse-cdn.com/v4/letter/z/f6c823/32.png) [@zhaoquanzheng](https://discourse.julialang.org/u/zhaoquanzheng)
#### Post date: [July 22, 2020, 4:59am UTC](https://discourse.julialang.org/t/regex-numeric-range-generator/43472/1 "2020-07-22T04:59:10Z")

</div>

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](https://stackoverflow.com/questions/33512037/a-regular-expression-generator-for-number-ranges)). 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.

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [July 22, 2020, 8:26am UTC](https://discourse.julialang.org/t/regex-numeric-range-generator/43472/2 "2020-07-22T08:26:11Z")

</div>

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.

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757/):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …

---

<div class="post-metadata">

### Author: ![zhaoquanzheng](https://avatars.discourse-cdn.com/v4/letter/z/f6c823/32.png) [@zhaoquanzheng](https://discourse.julialang.org/u/zhaoquanzheng)
#### Post date: [July 22, 2020, 11:35am UTC](https://discourse.julialang.org/t/regex-numeric-range-generator/43472/3 "2020-07-22T11:35:24Z")

</div>

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 :

```julia
...
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)

```julia
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)?

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [July 22, 2020, 11:50am UTC](https://discourse.julialang.org/t/regex-numeric-range-generator/43472/4 "2020-07-22T11:50:28Z")

</div>

> [@zhaoquanzheng](#):
>
> 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.
