My initial instinct: no, such a library does not exist, because it is impossible. You cannot be sure that you can find a valid input for any arbitrary regular expression in a reasonable amount of time.
For example, proving whether a number is prime is difficult to solve a mathematical problem. The following regular expression matches any string with a length of at least 10,000 characters and whose total length is a prime:
(?!(..+)\1+$).{10000}
I doubt that there is any library that can find the correct input for this regular expression in a reasonable amount of time. And this is a very simple example with a simple solution, for example. 'x' * 10007 will work. It would be possible to come up with other regular expressions that are much harder to find valid values ββfor.
I think the only way to solve this problem is to limit yourself to a certain subset of all possible regular expressions.
But, saying that if you have a magic library that generates text that matches any arbitrary regular expression, then all you have to do is create a regular expression that matches all the lines that don't match your original expression.
Fortunately, this is possible with a negative view:
^(?![\s\S]*(?:^[abcd]d+))
If you want to change the requirements to allow a limited subset of regular expressions, you can negate the regular expression using logical logic. For example, if ^[abcd]d+ becomes ^[^abcd]|^[abcd][^d] . You can then find the correct input for this regular expression in a reasonable amount of time.
source share