Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Latest commit

 

History

History
51 lines (40 loc) · 792 Bytes

README.md

File metadata and controls

51 lines (40 loc) · 792 Bytes

Reg-gen

This package generates strings based on regular expressions

Try it here

Usage

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