-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b32279b
commit 6cc1545
Showing
2 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,60 @@ | ||
# wildcard | ||
|
||
A simple golang wildcard matcher. Golang has pretty well built regex functionalities, but it does not have 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. | ||
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 support 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 or `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) | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
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) | ||
} |