Skip to contents

Translates an aws s3 sync glob into an anchored regex, following Python's fnmatch (which aws s3 sync filters use): * = any run of characters (including / and the empty string), ? = one character, [seq] = one character in seq (ranges like [0-9] allowed), [!seq] = one character not in seq, everything else literal. An unclosed [ is literal. Used by schema_glob_check(). The result is a PCRE regex: match with perl = TRUE (escapes inside [...] are not portable to R's default TRE engine).

Usage

glob_to_regex(x)

Arguments

x

(character(1))
Glob pattern.

Value

(character(1))
Anchored PCRE regex equivalent.

Examples

(r1 <- glob_to_regex("*.purple.qc"))
#> [1] "^.*\\.purple\\.qc$"
(r2 <- glob_to_regex("*purple/*.purple.qc"))
#> [1] "^.*purple/.*\\.purple\\.qc$"