
Match file paths using Unix shell-style globs (*, ?, [], {}, **) with efficient single-pattern and glob-set matching, optional case-insensitive and literal modes, and path-separator awareness.
globset-kotlin is a Kotlin Multiplatform library for matching file paths against Unix shell-style glob patterns. It provides efficient single glob and glob set matching across all Kotlin platforms.
*, ?, [...], {a,b}, and ** patternsAdd the dependency to your build.gradle.kts:
dependencies {
implementation("io.github.kotlinmania:globset-kotlin:0.1.2")
}Or in your build.gradle:
dependencies {
implementation 'io.github.kotlinmania:globset-kotlin:0.1.2'
}import io.github.kotlinmania.globset.GlobBuilder
// Match a simple pattern
val glob = GlobBuilder("*.txt").build()
assert(glob.isMatch("file.txt"))
assert(!glob.isMatch("file.rs"))
// Case-insensitive matching
val caseInsensitive = GlobBuilder("*.TXT")
.caseInsensitive(true)
.build()
assert(caseInsensitive.isMatch("file.txt"))Match multiple patterns efficiently:
import io.github.kotlinmania.globset.GlobSetBuilder
val set = GlobSetBuilder()
.add("*.rs")
.add("*.toml")
.add("src/**/*.kt")
.build()
// Check if any pattern matches
assert(set.isMatch("src/main.rs"))
assert(set.isMatch("Cargo.toml"))
assert(set.isMatch("src/lib/utils.kt"))
assert(!set.isMatch("README.md"))
// Get all matching patterns
val matches = set.matches("src/main.rs")
println("Matched patterns: $matches")globset-kotlin supports standard Unix shell glob patterns:
? - Matches any single character except path separators* - Matches zero or more characters except path separators** - Matches zero or more directories (must be a complete path component)[abc] - Matches any character inside the brackets[!abc] or [^abc] - Matches any character not in the brackets[a-z] - Matches any character in the range{a,b,c} - Matches any of the comma-separated patterns*.txt # Matches: file.txt, document.txt
src/*.kt # Matches: src/Main.kt, src/Utils.kt
**/*.rs # Matches: src/lib.rs, foo/bar/baz.rs
test_?.rs # Matches: test_1.rs, test_a.rs
[abc]*.txt # Matches: a_file.txt, book.txt
{foo,bar}/* # Matches: foo/file.txt, bar/doc.rs
globset-kotlin is a Kotlin Multiplatform library supporting:
# Build for all platforms
./gradlew build
# Run tests
./gradlew test
# Build for a specific platform
./gradlew jvmTest
./gradlew macosArm64Test
./gradlew jsNodeTestThis is an in-progress port from the upstream Rust globset crate (part of ripgrep). The goal is feature parity with the upstream while providing a native Kotlin Multiplatform API.
Currently implemented:
See PORT_REPORT.md for detailed porting status.
API documentation is available on Maven Central.
Contributions are welcome! This project follows a systematic porting approach:
// port-lint: source <path> header linking to its upstream Rust sourceSee AGENTS.md for detailed contribution guidelines.
This project is released into the public domain under the Unlicense.
See LICENSE for the full license text.
Original Rust implementation: Copyright (c) 2016-2024 Andrew Gallant and contributors Kotlin port: Copyright (c) 2026 Sydney Renee and The Solace Project
This is a faithful port of the globset crate from ripgrep. All design credit belongs to Andrew Gallant (BurntSushi) and the ripgrep contributors. This Kotlin implementation preserves their excellent API design while bringing it to the Kotlin Multiplatform ecosystem.
If you're working with file system operations in Kotlin, you might also be interested in:
.gitignore-style file filteringMade with ❤️ by Sydney Renee and The Solace Project
globset-kotlin is a Kotlin Multiplatform library for matching file paths against Unix shell-style glob patterns. It provides efficient single glob and glob set matching across all Kotlin platforms.
*, ?, [...], {a,b}, and ** patternsAdd the dependency to your build.gradle.kts:
dependencies {
implementation("io.github.kotlinmania:globset-kotlin:0.1.2")
}Or in your build.gradle:
dependencies {
implementation 'io.github.kotlinmania:globset-kotlin:0.1.2'
}import io.github.kotlinmania.globset.GlobBuilder
// Match a simple pattern
val glob = GlobBuilder("*.txt").build()
assert(glob.isMatch("file.txt"))
assert(!glob.isMatch("file.rs"))
// Case-insensitive matching
val caseInsensitive = GlobBuilder("*.TXT")
.caseInsensitive(true)
.build()
assert(caseInsensitive.isMatch("file.txt"))Match multiple patterns efficiently:
import io.github.kotlinmania.globset.GlobSetBuilder
val set = GlobSetBuilder()
.add("*.rs")
.add("*.toml")
.add("src/**/*.kt")
.build()
// Check if any pattern matches
assert(set.isMatch("src/main.rs"))
assert(set.isMatch("Cargo.toml"))
assert(set.isMatch("src/lib/utils.kt"))
assert(!set.isMatch("README.md"))
// Get all matching patterns
val matches = set.matches("src/main.rs")
println("Matched patterns: $matches")globset-kotlin supports standard Unix shell glob patterns:
? - Matches any single character except path separators* - Matches zero or more characters except path separators** - Matches zero or more directories (must be a complete path component)[abc] - Matches any character inside the brackets[!abc] or [^abc] - Matches any character not in the brackets[a-z] - Matches any character in the range{a,b,c} - Matches any of the comma-separated patterns*.txt # Matches: file.txt, document.txt
src/*.kt # Matches: src/Main.kt, src/Utils.kt
**/*.rs # Matches: src/lib.rs, foo/bar/baz.rs
test_?.rs # Matches: test_1.rs, test_a.rs
[abc]*.txt # Matches: a_file.txt, book.txt
{foo,bar}/* # Matches: foo/file.txt, bar/doc.rs
globset-kotlin is a Kotlin Multiplatform library supporting:
# Build for all platforms
./gradlew build
# Run tests
./gradlew test
# Build for a specific platform
./gradlew jvmTest
./gradlew macosArm64Test
./gradlew jsNodeTestThis is an in-progress port from the upstream Rust globset crate (part of ripgrep). The goal is feature parity with the upstream while providing a native Kotlin Multiplatform API.
Currently implemented:
See PORT_REPORT.md for detailed porting status.
API documentation is available on Maven Central.
Contributions are welcome! This project follows a systematic porting approach:
// port-lint: source <path> header linking to its upstream Rust sourceSee AGENTS.md for detailed contribution guidelines.
This project is released into the public domain under the Unlicense.
See LICENSE for the full license text.
Original Rust implementation: Copyright (c) 2016-2024 Andrew Gallant and contributors Kotlin port: Copyright (c) 2026 Sydney Renee and The Solace Project
This is a faithful port of the globset crate from ripgrep. All design credit belongs to Andrew Gallant (BurntSushi) and the ripgrep contributors. This Kotlin implementation preserves their excellent API design while bringing it to the Kotlin Multiplatform ecosystem.
If you're working with file system operations in Kotlin, you might also be interested in:
.gitignore-style file filteringMade with ❤️ by Sydney Renee and The Solace Project