4 个版本

0.1.3 2019 年 7 月 16 日
0.1.2 2019 年 6 月 8 日
0.1.1 2019 年 6 月 8 日
0.1.0 2019 年 6 月 8 日

#1250 in 文件系统

Download history 44/week @ 2024-04-04 22/week @ 2024-04-11 13/week @ 2024-04-18 34/week @ 2024-04-25 28/week @ 2024-05-02 11/week @ 2024-05-09 19/week @ 2024-05-16 17/week @ 2024-05-23 15/week @ 2024-05-30 26/week @ 2024-06-06 22/week @ 2024-06-13 12/week @ 2024-06-20 13/week @ 2024-06-27 22/week @ 2024-07-04 5/week @ 2024-07-11 28/week @ 2024-07-18

每月 70 次下载

MIT 许可证

38KB
772

globber

Build Status Docs

此包提供字符串与扩展 glob 模式的匹配。目前仅支持匹配,实际的文件系统查找将在路线图中实现。

如果您需要文件系统查找,请查看glob 包,它非常出色,并且是此包的主要灵感来源。

用法

将以下内容添加到您的 Cargo.toml

[dependencies]
globber = "0.1"

示例

通配符

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"));

范围

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"));

模式

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"));

语法

基本

?           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

扩展

?(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

模式可以是任何有效的 glob 模式,例如,!(+(ab|def)*+(.jpg|.gif))

无运行时依赖