er

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 9, 2020 License: MIT Imports: 6 Imported by: 0

README ΒΆ

ER - re regexp

version license Go Report Card

πŸ›  Installation

As Executable
  • If you have go in your system, what you need to do just use go get

    go get -u github.com/unbyte/er/cmd/er
    er --help
    
  • In other case, you need go to download executable in Release Page, and then rename the executable to er ( or er.exe on window ).

As Package

If you want to use er as a go package, please go get -u github.com/unbyte/er.

🎨 Usage

As Executable
> er --help
Usage of ER CLI:
  -a, -amount int
        amount of strings to be generated. default to 1. (default 1)
  -p, -pattern string
        pattern string

Syntax: https://golang.org/pkg/regexp/syntax/
Unicode Class: https://en.wikipedia.org/wiki/Unicode_character_property

> er -p "\d{3}-\d{8}|\d{4}-\d{7}" -a 10
454-16390004
0913-1976506
543-75125853
280-27961072
5049-7522609
7833-1752530
822-89737417
7176-8019427
5181-6167904
090-60481568

> er -p "[πŸ˜‚-😍]+"
πŸ˜‡πŸ˜…πŸ˜‹πŸ˜ŠπŸ˜ƒπŸ˜‰πŸ˜ŠπŸ˜‚πŸ˜†πŸ˜πŸ˜ŠπŸ˜ˆπŸ˜πŸ˜‡πŸ˜πŸ˜„πŸ˜‡πŸ˜πŸ˜‚πŸ˜†πŸ˜‰πŸ˜ŒπŸ˜…πŸ˜…πŸ˜ŠπŸ˜ƒπŸ˜ƒπŸ˜‡πŸ˜‚πŸ˜ŒπŸ˜‰πŸ˜‹πŸ˜‰πŸ˜†πŸ˜†πŸ˜‚πŸ˜„πŸ˜πŸ˜‚πŸ˜πŸ˜‡πŸ˜„πŸ˜ƒπŸ˜„πŸ˜‚πŸ˜ˆπŸ˜‚πŸ˜ŒπŸ˜‰πŸ˜ŒπŸ˜…πŸ˜‡πŸ˜‚

You can get the syntax of regexp here

and get all unicode groups here

As Package
import (
    "github.com/unbyte/er"
    "regexp/syntax"
)
func main(){
    pattern := "^[A-Za-z_]{10,14}$"
    generator, err := er.Parse(pattern, syntax.Perl)
    if err != nil {
        panic(err)
    }

    s, err := generator.Generate()
    if err != nil {
        panic(err)
    }
    fmt.Println(s)

    ss, err := generator.GenerateMultiple(10)
    if err != nil {
        panic(err)
    }
    fmt.Println(strings.Join(ss, "\n"))
}

πŸ“„ License

MIT LICENSE.

Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

This section is empty.

Variables ΒΆ

This section is empty.

Functions ΒΆ

func Generate ΒΆ

func Generate(regexp *syntax.Regexp) (string, error)

Generate a random string according to *syntax.Regexp ( got by syntax.Parse() )

func RandAscii ΒΆ

func RandAscii() rune

return a random visible ascii

func RandBool ΒΆ

func RandBool() bool

return a random boolean

func RandInRange ΒΆ

func RandInRange(min, max int) int

return an int in range [min, max]

func RandInt ΒΆ

func RandInt(max int) int

return a random int in range [0, max)

func RandRepeat ΒΆ

func RandRepeat(min, max int) int

return an int in range [min, max].

if max is -1, then it will be set to defaultMax (math.MaxInt8 >> 1)

func RandRune ΒΆ

func RandRune(runeGroup []rune) rune

random rune

runeGroup => []rune{lowA, highA, lowB, highB, ...}, and will return a rune between lowA and highA, or lowB and highB

Types ΒΆ

type Generator ΒΆ

type Generator interface {
	// Generator a random string
	Generate() (string, error)

	// Generator multiple strings
	GenerateMultiple(amount int) ([]string, error)
}

Generator generate string(s)

func Parse ΒΆ

func Parse(pattern string, flags syntax.Flags) (Generator, error)

Parse a pattern string and return a Generator if success

Directories ΒΆ

Path Synopsis
cmd
er

Jump to

Keyboard shortcuts

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