#glob #extended #matching

globber

Extended glob matching library

4 releases

0.1.3 Jul 16, 2019
0.1.2 Jun 8, 2019
0.1.1 Jun 8, 2019
0.1.0 Jun 8, 2019

#1 in #extended

Download history 56/week @ 2023-10-25 30/week @ 2023-11-01 33/week @ 2023-11-08 21/week @ 2023-11-15 31/week @ 2023-11-22 67/week @ 2023-11-29 16/week @ 2023-12-06 36/week @ 2023-12-13 46/week @ 2023-12-20 39/week @ 2023-12-27 55/week @ 2024-01-03 39/week @ 2024-01-10 29/week @ 2024-01-17 39/week @ 2024-01-24 32/week @ 2024-01-31 28/week @ 2024-02-07

134 downloads per month

MIT license

38KB
772 lines

globber

Build Status Docs Crate

This crate provides matching of strings to extended glob patterns. Only matching is supported currently and actual filesystem look up is on the road map.

If you need filesystem look up the glob crate is amazing and was a major inspiration for this crate.

Usage

Add the following to your Cargo.toml

[dependencies]
globber = "0.1"

Examples

Wildcards

let pattern = Pattern::new("*.rs").unwrap();
assert!(pattern.matches("hey.rs"));
assert!(!pattern.matches("hey.c"));
assert!(pattern.matches("/src/test.rs"));
assert!(!pattern.matches("/src/test.c"));

Ranges

let pattern = Pattern::new("[a-z].rs").unwrap();
assert!(pattern.matches("a.rs"));
assert!(pattern.matches("d.rs"));
assert!(pattern.matches("z.rs"));
assert!(!pattern.matches("A.rs"));
assert!(!pattern.matches("Z.rs"));
assert!(!pattern.matches("0.rs"));

Patterns

let pattern = Pattern::new("!([a-z]).rs").unwrap();
assert!(!pattern.matches("a.rs"));
assert!(!pattern.matches("d.rs"));
assert!(!pattern.matches("z.rs"));
assert!(pattern.matches("A.rs"));
assert!(pattern.matches("Z.rs"));
assert!(pattern.matches("0.rs"));

Syntax

Basic

?           is any character
*           any sqeunece of characters
**          matches zero or more sqeuneces of characters
[abc]       matches one character given in the bracket
[a-z]       matches a character in the range inclusively
[!abc]      does not match one character given in the bracket
[!a-z]      does not match a character in the range inclusively

Extended

?(pattern|pattern|pattern) matches zero or one of the patterns
*(pattern|pattern|pattern) matches zero or more of the patterns
+(pattern|pattern|pattern) matches ine or more of the patterns
@(pattern|pattern|pattern) matches exactly one of the patterns
!(pattern|pattern|pattern) matches none of the patterns

A pattern is any valid glob pattern e.g, !(+(ab|def)*+(.jpg|.gif))

No runtime deps