lucasjones / Reggen
Licence: mit
Go package to generate text from regex definitions
Stars: ✭ 54
Programming Languages
go
31211 projects - #10 most used programming language
Reg-gen
This package generates strings based on regular expressions
here
Try itUsage
package main
import (
"fmt"
"github.com/lucasjones/reggen"
)
func main() {
// generate a single string
str, err := reggen.Generate("^[a-z]{5,10}@[a-z]{5,10}\\.(com|net|org)$", 10)
if err != nil {
panic(err)
}
fmt.Println(str)
// create a reusable generator
g, err := reggen.NewGenerator("[01]{5}")
if err != nil {
panic(err)
}
for i := 0; i < 5; i++ {
// 10 is the maximum number of times star, range or plus should repeat
// i.e. [0-9]+ will generate at most 10 characters if this is set to 10
fmt.Println(g.Generate(10))
}
}
Sample output:
[email protected]
11000
01010
01100
01111
01001
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].