https://github.com/vodkaslime/wildcard
A simple golang customizable wildcard matcher.
https://github.com/vodkaslime/wildcard
golang matcher simple tool wildcard
Last synced: 5 months ago
JSON representation
A simple golang customizable wildcard matcher.
- Host: GitHub
- URL: https://github.com/vodkaslime/wildcard
- Owner: vodkaslime
- License: mit
- Created: 2022-09-25T15:15:48.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-09-26T07:04:10.000Z (over 3 years ago)
- Last Synced: 2023-08-09T15:20:36.631Z (almost 3 years ago)
- Topics: golang, matcher, simple, tool, wildcard
- Language: Go
- Homepage:
- Size: 12.7 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# wildcard
A simple golang customizable [wildcard](https://en.wikipedia.org/wiki/Wildcard_character) matcher. Golang has pretty well built regex functionalities, but it does not have basic wildcard matcher that works as nicely. Therefore this package serves the need to check whether a string matches a pattern in the rule of wildcard.
To keep simplicity, the matcher supports only two rules:
- `"?"` for a single char.
- `"*"` for any number (including zero) of chars.
Charset like `"[A-Za-z]"` or SQL style wild cards like `%` are not supported.
## usage
To import the package, `go get` the module.
```
go get -u github.com/vodkaslime/wildcard@main
```
To match pattern, use a matcher.
```
package main
import (
"github.com/vodkaslime/wildcard"
)
func main() {
matcher := wildcard.NewMatcher()
p := "a?c"
s := "abc"
m, _ := matcher.Match(p, s)
println(m)
}
```
The default wildcard chars are `"?"` for single chars and `"*"` for multiple chars. To customize this rule, tune the `S` field and `M` field accordingly.
For example to use `"."` as single char wildcard symbol:
```
package main
import (
"github.com/vodkaslime/wildcard"
)
func main() {
matcher := wildcard.NewMatcher()
matcher.S = '.'
p := "a.c"
s := "abc"
m, _ := matcher.Match(p, s)
println(m)
}
```