reggen

package module
v0.0.0-...-11b9640 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 3, 2023 License: MIT Imports: 3 Imported by: 0

README

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:
bxnpubwc@kwrdbvjic.com
11000
01010
01100
01111
01001

Documentation

Overview

Package reggen generates text based on regex definitions

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(re *syntax.Regexp, limit int, rand *rand.Rand) string

limit 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

func GenerateFromString

func GenerateFromString(re string, limit int, rand *rand.Rand) (string, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL