genex

package module
v0.0.0-...-2f0294e Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2020 License: MIT Imports: 2 Imported by: 1

README

genex GoDoc GoCover Go Report Card

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.

Usage

package main

import (
    "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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Count

func Count(input, charset *syntax.Regexp, infinite int) float64

Count computes the total number of matches the `input` regex would generate after whitelisting `charset`. The `infinite` argument caps the maximum boundary of repetition operators.

func Generate

func Generate(input, charset *syntax.Regexp, infinite int, callback func(string))

Generate yields all the strings that match the `input` regex after whitelisting `charset`. The `infinite` argument caps the maximum boundary of repetition operators.

Types

This section is empty.

Jump to

Keyboard shortcuts

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