regen

command module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 25, 2018 License: BSD-2-Clause Imports: 10 Imported by: 0

README

regen

$ go get go.spiff.io/regen

regen is a small tool to generate more or less random strings from Go RE2 regular expressions. You can read up on RE2 at https://github.com/google/re2/wiki/Syntax.

As a few examples:

$ regen -n 2 '0x[\da-f]{16}'
0x8f5858102a5ce124
0x3e4c9fee6c9f419d

$ regen -n 3 '[a-z]{6,12}(\+[a-z]{6,12})?@[a-z]{6,16}(\.[a-z]{2,3}){1,2}'
iprbph+gqastu@regegzqa.msp
abxfcomj@uyzxrgj.kld.pp
vzqdrmiz@ewdhsdzshvvxjk.pi

Essentially, all regen does is parse the regular expressions it's given and iterate over the tree produced by regexp/syntax and attempt to generate strings based on the ops described by its results. This could probably be optimized further by compiling the resulting Regexp into a Prog, but I didn't feel like this was worthwhile when it's a very small tool.

Currently, handling word boundaries is not supported and will cause regen to panic in response. The way line endings and EOT is handled are also likely incorrect and they'll need some more thinking put into them.

Some additional information can be found at https://godoc.org/go.spiff.io/regen.

Contributing

Currently, development of regen is happening over at https://git.spiff.io. If you'd like to submit a patch, please first open an issue on GitHub to discuss what you'd like to do and we can go from there. regen does not currently accept pull requests because changes are replicated from Gerrit to GitHub, but not vice versa.

License

regen is licensed under a 2-clause BSD license. This can be found in LICENSE.txt.

Documentation

Overview

regen is a tool to parse and generate random strings from regular expressions.

go get go.spiff.io/regen

regen works by parsing a regular expression and walking its op tree. It is currently not guaranteed to produce entirely accurate results, but will at least try.

Currently, word boundaries are not supported (until I decide how best to randomly insert a word boundary character). Using a word boundary op (\b or \B) will currently cause regen to panic. In addition, line endings are also poorly supported right now and EOT markers are treated as the end of string generation.

Usage is simple, pass one or more regular expressions to regen on the command line and it will generate a string from each, printing them in the same order as on the command line (separated by newlines):

$ regen 'foo(-(bar|baz|quux|woop)){4}'
foo-woop-quux-bar-quux

So, if you fancy yourself a Javascript weirdo of some variety, you can at least use regen to write code for eBay:

$ regen '!{0,5}\[\](\[(!\[\](\+!{1,2}\[\]))\]|\+!{0,5}\[(\[\])?\]|\+\{\})+'
![]+!!![[]]+{}[![]+!![]][![]+!![]]+{}[![]+![]]+{}+{}[![]+![]][![]+!![]]+![[]]+{}

A few command-line options are provided, which you can see by running regen -help.

Jump to

Keyboard shortcuts

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