Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reverse regular expressions to generate data

In one of the StackOverflow Podcasts (the one where guys were discussing data generation for testing DBs -- either #11 or #12), Jeff mentioned something like "reverse regular expressions", which are used exactly for that purpose: given a regex, produce a string which will eventually match said regex.

What is the correct term for this whole concept? Is this a well-known concept?

like image 414
Anton Gogolev Avatar asked May 25 '10 13:05

Anton Gogolev


People also ask

How do you reverse a regular expression?

Another way to show that reverse(L) is regular is via regular expressions. For any regular expression r you can construct a regular expression r such that L(r ) = reverse(L) using the inductive definition of regular languages.

What is RegEx generator?

"Regex Generator is a simple web interface to generate regular expressions from a set of strings."

Does RegEx backtrack?

The regular expression engine does not backtrack because {2} is not an optional quantifier; it specifies an exact number and not a variable number of times that the previous subexpression must match.

What is '?' In regular expression?

'?' matches/verifies the zero or single occurrence of the group preceding it. Check Mobile number example. Same goes with '*' . It will check zero or more occurrences of group preceding it.


1 Answers

The Perl module String::Random (in the CPAN) does this. Takes a subset of regular expressions, and does a random walk through it.

like image 113
Randal Schwartz Avatar answered Oct 04 '22 03:10

Randal Schwartz