#pattern-matching #group #unix-shell #capture #file-path #glob-pattern #range

capturing-glob

An extension for unix shell style globs that allow to capture groups (i.e. remember matching character ranges) while matching.

2 releases

Uses old Rust 2015

0.1.1 Feb 9, 2018
0.1.0 Dec 15, 2017

#974 in Filesystem

Download history 715/week @ 2024-07-22 390/week @ 2024-07-29 467/week @ 2024-08-05 201/week @ 2024-08-12 213/week @ 2024-08-19 202/week @ 2024-08-26 163/week @ 2024-09-02 127/week @ 2024-09-09 162/week @ 2024-09-16 147/week @ 2024-09-23 186/week @ 2024-09-30 157/week @ 2024-10-07 644/week @ 2024-10-14 193/week @ 2024-10-21 331/week @ 2024-10-28 206/week @ 2024-11-04

1,375 downloads per month
Used in 2 crates

MIT/Apache

74KB
1.5K SLoC

Capturing Glob

Documentation | Github | Crate

Support for matching file paths against Unix shell style patterns, and capture groups when matching (similarly to captures in regexes).

Usage

And add this to your crate root:

extern crate capturing_glob;

Examples

Print all jpg files in /media/ and all of its subdirectories.

use capguring_glob::glob;

for entry in glob("/media/**/(*).jpg").expect("Failed to read glob pattern") {
    match entry {
        Ok(entry) => println!("Path {:?}, name {:?}",
            entry.path().display(), entry.group(1).unwrap()),
        Err(e) => println!("{:?}", e),
    }
}

Note: in the case above, regular filename matching might be used (i.e. file_stem()), but the library allows you to skip unwraps here, but more importantly you can use user-defined globs like these:

  • (*)/package.json
  • tests/(*).spec.js
  • docs/(section-*).rst
  • /usr/share/zoneinfo/(*/*)

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

No runtime deps