Edit:
Complete list of suggested libraries on this question:
- Xeger* - Java
- Generex* - Java
- Rgxgen - Java
- rxrdg - C#
* - Depends on dk.brics.automaton
Edit:
As mentioned in the comments, there is a library available at Google Code to achieve this:
https://code.google.com/archive/p/xeger/
See also https://github.com/mifmif/Generex as suggested by Mifmif
Original message:
Firstly, with a complex enough regexp, I believe this can be impossible. But you should be able to put something together for simple regexps.
If you take a look at the source code of the class java.util.regex.Pattern, you'll see that it uses an internal representation of Node instances. Each of the different pattern components have their own implementation of a Node subclass. These Nodes are organised into a tree.
By producing a visitor that traverses this tree, you should be able to call an overloaded generator method or some kind of Builder that cobbles something together.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…