Skip to content

Please add an option for "?" to also match "/"

I'd like to use fnmatch-regex with strings other than filenames, but the problem is that the "?" character gets translated to the regex "[^/]", which is fine for filenames, but not good for other strings. It would be great to add a second function, like glob_to_regex_with(pattern: &str, options: &GlobOptions)

While we're at it, GlobOptions could include an option to not match the whole string (again useful if not dealing with path names), and an option to disable the {a,bbb,cc} alternation:

struct GlobOptions {
    pub match_slash: bool,
    pub match_whole_string: bool,
    pub enable_alternation: bool,
}

so if the match_slash option is set to true, then "?" could be translated as "."; if the match_whole_string option is set to false, the regex will not begin with ^ and end with $; and if the enable_alternation option is set to false, then {a,bb,ccc} will not be treated as an alternation (glob usually consists only of "?", "*", and character classes).

Edited by Franco Bugnano