Skip to main content

glob_to_regex

Function glob_to_regex 

Source
pub fn glob_to_regex(glob: &str) -> String
Expand description

Convert a glob pattern into an (unanchored) regular-expression source.

* and ? do not cross a path separator (/), mirroring shell glob semantics; [ … ] character classes are passed through (with a leading ! rewritten to the regex negation ^); every other regex metacharacter is escaped to a literal.

§Examples

use coding_tools::pattern::glob_to_regex;

assert_eq!(glob_to_regex("*.rs"), r"[^/]*\.rs");
assert_eq!(glob_to_regex("data_[0-9]"), "data_[0-9]");