Greex is a Java library that can be used to generate matches for regular expressions. It supports both random generation as well as complete generation. This can be used for creating test data, generating random tokens, or creating unit test cases.
How to Use Greex
To use Greex, add it as a dependency with your favorite build tool, or download the JAR and the brics automata JAR and add it to your classpath. Greex is available on Maven Central.
Once it's added to your classpath, you can use the GreexGenerator class to start generating matches for your regular expressions. For example:
GreexGeneratorgenerator=newGreexGenerator("(white|black)|((light|dark) )?(red|green|blue|gray)");
Stringmatch= generator.generateRandom();
System.out.println(match); // e.g. "dark red"
generateRandom does exactly what it says: it generates random matches based on the input regex for the generator. Similarly, you can also generate all of the matches for a given regular expression. For example:
This generates all possible matches with 10 or fewer characters.
Problems Greex Solves
Primarily, Greex is most useful for unit testing, but it can also be used for token, ID, or password generation.
Unit Testing
Often times when working with regular expressions, it can be hard to get coverage of different matching values to ensure that downstream code behaves properly with many different kinds of matches. Greex can be used to generate a set of random matches (or all matches, when applicable) of a regular expression that can then be used to do unit testing on code.
Since it supports taking existing instances of java.util.Random or custom seed values, it can also be set up to consistently produce the same values when generating random matches so that unit tests can be stable.
Value Generation
When generating values for a system, e.g. IDs or passwords, you can supply a regex that can be used to generate a random value that matches your requirements for the value's format. For example, to generate a securely random, 12-character, alphanumeric password:
The regex can be further tweaked to meet security requirements, readability requirements, etc.
FAQs
Regex match generation for generating random strings or for creating unit test cases based on regular expressions.
We found that com.navigamez:greex demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Package last updated on 07 Dec 2017
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Socket found a Rust typosquat (finch-rust) that loads sha-rust to steal credentials, using impersonation and an unpinned dependency to auto-deliver updates.
A pair of typosquatted Go packages posing as Googleâs UUID library quietly turn helper functions into encrypted exfiltration channels to a paste site, putting developer and CI data at risk.