glob_to_regex

function of dascore.io.index.query source

glob_to_regex(
    pattern: str ,
)-> ‘re.Pattern’

Translate a glob to the regex which matches what SQLite’s GLOB does.

SQLite is the authority on what a glob selector means, since that is what the index applies, and it is not fnmatch: a character class is negated with [^...], where fnmatch spells that [!...] and reads a leading ! as a literal. Translating here rather than reaching for fnmatch is what keeps one pattern from selecting opposite halves of a spool depending on which side answered it. An unterminated class matches nothing, as it does in SQLite; a class a regex cannot express at all (a reversed range, which SQLite reads leniently) matches nothing here rather than being guessed at.