https://github.com/maolonglong/redglob
🐹 redglob is a simple glob-style pattern matcher library for Go, inspired by Redis's pattern matching implementation.
https://github.com/maolonglong/redglob
glob go golang match pattern-matching unicode
Last synced: about 1 year ago
JSON representation
🐹 redglob is a simple glob-style pattern matcher library for Go, inspired by Redis's pattern matching implementation.
- Host: GitHub
- URL: https://github.com/maolonglong/redglob
- Owner: maolonglong
- License: apache-2.0
- Created: 2023-05-17T12:52:14.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2025-03-24T19:53:37.000Z (about 1 year ago)
- Last Synced: 2025-03-24T23:41:18.523Z (about 1 year ago)
- Topics: glob, go, golang, match, pattern-matching, unicode
- Language: Go
- Homepage:
- Size: 42 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Redglob
[](https://pkg.go.dev/github.com/maolonglong/redglob)
[](https://github.com/maolonglong/redglob/actions/workflows/go.yml)
[](https://codecov.io/gh/maolonglong/redglob)
[](https://goreportcard.com/report/github.com/maolonglong/redglob)
Redglob is a simple glob-style pattern matcher library for Go, inspired by Redis's pattern matching implementation. It provides a fast and easy-to-use solution for matching strings and byte slices against patterns with wildcard support.
## Features
- Unicode support
- Case-insensitive matching
- Capability to match strings and byte slices
- Supports `*`, `?`, character classes `[abc]`, ranges `[a-z]`, and negation `[^abc]`
## Installing
```bash
go get github.com/maolonglong/redglob
```
## Usage
```go
package main
import (
"fmt"
"github.com/maolonglong/redglob"
)
func main() {
pattern := "h?ll*"
str := "hello, world!"
if redglob.Match(str, pattern) {
fmt.Println("Match!")
} else {
fmt.Println("No match.")
}
}
```
## Functions
- `Match(str, pattern string) bool`: returns true if the given string matches the pattern.
- `MatchFold(str, pattern string) bool`: case-insensitive version of `Match`.
- `MatchBytes(b []byte, pattern string) bool`: similar to `Match`, but accepts a byte slice instead of a string.
- `MatchBytesFold(b []byte, pattern string) bool`: case-insensitive version of `MatchBytes`.
## Syntax
Redglob's pattern syntax is similar to that of Redis's `KEYS` command:
- `*` matches any sequence of non-Separator characters
- `?` matches any single non-Separator character
- `c` matches character `c` (where `c` is any character except `*`, `?`, and `\`)
- `\c` matches character `c`
- `[abc]` matches `a` or `b` or `c`
- `[^abc]` matches any character except `a`, `b`, or `c`
- `[a-z]` matches `a` to `z`
- `[^a-z]` matches any character except `a` to `z`
## Performance
Redglob is implemented in pure Go and is optimized for performance. It uses a simple and efficient algorithm to match patterns against strings, and takes advantage of Go's built-in Unicode support to handle Unicode characters correctly.
## License
Redglob is licensed under the Apache License, Version 2.0. See the [LICENSE file](LICENSE) for details.