I am looking for a way to list all possible patterns from a finite regex (with no duplicates). Is there any source available?
Asked
Active
Viewed 504 times
4
-
@Artha Any language preference? – moinudin Jan 05 '11 at 14:51
-
Can you give an example of input and expected output? – Gumbo Jan 05 '11 at 15:07
-
Do you mean all possible matches from a regex? – Jan 05 '11 at 19:01
2 Answers
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;'
-
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