Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alixaxel/genex
Genex package for Go
https://github.com/alixaxel/genex
genex go golang regex regular-expression
Last synced: about 2 months ago
JSON representation
Genex package for Go
- Host: GitHub
- URL: https://github.com/alixaxel/genex
- Owner: alixaxel
- License: mit
- Created: 2015-03-09T19:24:16.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2020-01-05T18:10:35.000Z (almost 5 years ago)
- Last Synced: 2024-10-11T20:14:36.344Z (2 months ago)
- Topics: genex, go, golang, regex, regular-expression
- Language: Go
- Homepage: https://namegrep.com/
- Size: 12.7 KB
- Stars: 77
- Watchers: 5
- Forks: 8
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- awesome-go - genex - Count and expand Regular Expressions into all matching Strings. (Text Processing / Regular Expressions)
- awesome-go - genex - Genex package for Go - ★ 48 (Text Processing)
- awesome-go-extra - genex - 03-09T19:24:16Z|2020-01-05T18:10:35Z| (Bot Building / Regular Expressions)
README
# genex [![GoDoc](https://godoc.org/github.com/alixaxel/genex?status.svg)](https://godoc.org/github.com/alixaxel/genex) [![GoCover](http://gocover.io/_badge/github.com/alixaxel/genex)](http://gocover.io/github.com/alixaxel/genex) [![Go Report Card](https://goreportcard.com/badge/github.com/alixaxel/genex)](https://goreportcard.com/report/github.com/alixaxel/genex)
Genex package for Go
Easy and efficient package to expand any given regex into all the possible strings that it can match.
This is the code that powers [namegrep](https://namegrep.com/).
## Usage
```go
package mainimport (
"fmt"
"regexp/syntax""github.com/alixaxel/genex"
)func main() {
charset, _ := syntax.Parse(`[0-9a-z]`, syntax.Perl)if input, err := syntax.Parse(`(foo|bar|baz){1,2}\d`, syntax.Perl); err == nil {
fmt.Println("Count:", genex.Count(input, charset, 3))genex.Generate(input, charset, 3, func(output string) {
fmt.Println("[*]", output)
})
}
}
```## Output
```
Count: 120[*] foo0
[*] ...
[*] foo9
[*] foofoo0
[*] ...
[*] foofoo9
[*] foobar0
[*] ...
[*] foobar9
[*] foobaz0
[*] ...
[*] foobaz9
[*] bar0
[*] ...
[*] bar9
[*] barfoo0
[*] ...
[*] barfoo9
[*] barbar0
[*] ...
[*] barbar9
[*] barbaz0
[*] ...
[*] barbaz9
[*] baz0
[*] ...
[*] baz9
[*] bazfoo0
[*] ...
[*] bazfoo9
[*] bazbar0
[*] ...
[*] bazbar9
[*] bazbaz0
[*] ...
[*] bazbaz9
```## Install
go get github.com/alixaxel/genex
## License
MIT