http://www.perlmonks.org?node_id=479769


in reply to Reverse engineering regular expressions

Interesting problem, but I wonder why you would want to solve it.

If you "just" want something to help you explain a regex, Regex Coach is helpful.

If you want to support the perl code-extensions - (?{ ... }) and friends - you can't. Update: after some more reading, lookaheads are tricky too, you're probably restricted to "classical" regular expressions + a few extensions.

Generating a "minimal" string that would match a regex (i.e. drop everything with a * modifier, drop everything after a |, take the first character of a characterset etc) should not be too hard (famous last words...) as long as you get the parser right. I suggest you take an existing one like YAPE::Regex or Regexp::Parser.

Oh, and while I was looking for those modules on cpan, I also found Regexp::Genex - it seems to do what you want. :-)