https://github.com/suprematic/globus
Bash-like globbing patterns for Clojure(Script).
https://github.com/suprematic/globus
glob globbing wildcards
Last synced: 3 months ago
JSON representation
Bash-like globbing patterns for Clojure(Script).
- Host: GitHub
- URL: https://github.com/suprematic/globus
- Owner: suprematic
- License: epl-2.0
- Created: 2022-11-08T10:44:34.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2024-04-16T21:08:43.000Z (over 1 year ago)
- Last Synced: 2025-10-18T13:32:35.660Z (3 months ago)
- Topics: glob, globbing, wildcards
- Language: Clojure
- Homepage:
- Size: 32.2 KB
- Stars: 13
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Globus
[](https://clojars.org/io.github.suprematic/globus)
[](https://cljdoc.org/d/io.github.suprematic/globus)
Bash-like globbing patterns for Clojure(Script).
Supported pattern language constructs:
* `?`: matches any single character
* `*`: matches any string, including the empty string
* `[qwe]`: matches any single character in `#{\q \w \e}`
* `[^qwe]` or `[!qwe]`: matches any single character _not_ in `#{\q \w \e}`
* `[a-f]`: matches any single character between `\a` and `\f` (inclusive)
* `{one,two,three}`: matches anything that any of the patterns `one`, `two`
and `three` would match. This one is has slightly different semantics
than what e.g. bash does (because in bash curly braces are not actually a
part of the matching engine)
See the [tests](test/globus/) for more details and examples.
## Usage
```clojure
(require '[globus.core :as glob])
;; check if a string is a glob pattern (contains special symbols)
(glob/glob? "abc") ; => false
(glob/glob? "ab?c") ; => true
;; filter a sequence of strings
(glob/glob "a*" ["aaa" "bb" "cccc" "defg"]) ; => ("aaa")
(glob/glob "[^a]???" ["aaa" "bb" "cccc" "defg"]) ; => ("cccc" "defg")
;; ignorecase
(glob/glob "A*" ["aaa" "bb" "cccc" "defg"]) ; => ()
(glob/glob "A*" ["aaa" "bb" "cccc" "defg"] {:ignorecase true}) ; => ("aaa")
;; convert a pattern to a (string representation of a) regular expression
(glob/pattern->regex "{a.*,*b}") ; => "(?:(?:a\\..*)|(?:.*b))"
;; enumerate all possible expansions of a pattern
(glob/explode "[ab]{cd,efg,hi[j-m]}")
; =>
; ["acd"
; "aefg"
; "ahij"
; "ahik"
; "ahil"
; "ahim"
; "bcd"
; "befg"
; "bhij"
; "bhik"
; "bhil"
; "bhim"]
;; that fails for patterns that cannot be expanded (contain `*`, `?` or
;; `[^...])
(glob/explode "abc*") ; Exception is thrown
```
## Contributing
Run the project's tests:
$ clojure -T:build test
$ clojure -T:build test-node # ClojureScript tests
## License
Copyright © 2022-2024 Suprematic
Distributed under the Eclipse Public License.