4

I am looking for a way to list all possible patterns from a finite regex (with no duplicates). Is there any source available?

Toon Krijthe
  • 52,876
  • 38
  • 145
  • 202
Artha
  • 193
  • 7

2 Answers2

3

Although it won't cover some advanced features, and has its own share of other caveats, Regexp::Genex seems to be close to what you are looking for.

There's also this thread of PerlMonks which is relevant enough (as well as explaining how Regexp::Genex might not do for you, and some roll-yourself alternatives).

Otherwise, as per Jeffrey Friedl's Mastering Regular Expressions, you could use the /g modifier, coupled with the (?{CODE}) extension and a pattern that will never match, ala:

perl -E '$_ = 'Mastering Regular Expressions'; /(\p{L}*)(?{ say qq![$^N]! })(?!)/g;'
Community
  • 1
  • 1
Hugmeir
  • 1,249
  • 6
  • 9
  • Is there any fully developed code -- Regex::Genex was alpha and does not support ^ $ \G... – Artha Jan 06 '11 at 15:03
  • Not that I know, unfortunately - Maybe a combination of that example from Mastering Regular Expressions (if you really, really needed it, you could even use $& and friends instead of capturing groups.. I don't know whenever $^{MATCH} works inside (?{CODE}) blocks) plus String::Random could do the trick? – Hugmeir Jan 06 '11 at 15:09
0

A Haskell program based on Perl's Regexp::Genex can be found on Github and on Hackage.

According to the author, it was inspired by Regexp::Genex, but "uses a random-walk approach for character classes, instead of enumerating all possibilities."

waldyrious
  • 3,683
  • 4
  • 33
  • 41