A Swift port of Python's fnmatch
module with optional support for Bash 'globstar' behavior (**
).
.package(url: "https://github.com/ileitch/swift-filename-matcher.git", from: "0.0.0")
.product(name: "FilenameMatcher", package: "swift-filename-matcher")
bazel_dep(name = "swift-filename-matcher", version = "<version>")
let matcher = FilenameMatcher(
pattern: "**/*.swift",
options: [.globstar]
)
matcher.match(filename: "path/to/File.swift") // true
To obtain the regex for a given pattern:
FilenameMatcher.translate("**/File.swift") // (?s:(.*/)?File\.swift)\Z
See FilenameMatcherOptions for the options that can be passed to FilenameMatcher
. Note that 'globstar' support is enabled by default.