4 ms·
The regex as a value generator in this book is really quite good. I've been dying to see somebody write it up and stick it on CPAN.
by elblanco 16y ago
The regex as a value generator in this book is really quite good. I've been dying to see somebody write it up and stick it on CPAN.
- mst 16y agoWell, go for it then - that'd be awesome! If you tweet @shadowcat_mst when you're ready I'll make sure your PAUSE account gets approved quickly (you're also welcome to bug me about how to build dists etc., I'm always happy to walk people through their first upload). Note that if you already have an account and uploads, I apologise for not recognising who you are but you're still welcome to bug me if there's anything I can do to help :)
- elblanco 16y agoAppreciate the offer. Unfortunately it's item 100 on a to-do list of 100 atm.
- JadeNB 16y agoIt's been a while since I read the book, and I don't remember this use of regexes; but is it by chance covered under Ovid's HOP::Parser module (http://search.cpan.org/~ovid/HOP-Parser http://search.cpan.org/~ovid/HOP-Parser), or another in that family (http://search.cpan.org/search?query=HOP http://search.cpan.org/search?query=HOP)?
- mjd 16y agoIt's section 6.5, "Regex string generation". Page 272: "Given a regex, how can one generate a list of all the strings matched by the regex?"
- elblanco 16y agoI've been looking for such a beast in the wild for quite some time. I've seen a few on CPAN that'll take a regex (or some type of expression, or some limited dialect of regex) and spit out a few random strings. Even Microsoft's REX tool (http://research.microsoft.com/en-us/projects/rex/ http://research.microsoft.com/en-us/projects/rex/), which is the best I've seen, gives nondeterministic random results. Having a tool that would take a PCRE (or some subset of the language), apply some constraints on repetition operators (like *->{0,2}, +->{1,2}) etc., spit out a deterministic list of values (don't care how long so long as it's reasonably finite) would be extremely powerful for software testing. Even the rather limited capabilities in REX have helped me fix some invalid assumptions I was making about valid inputs. It's always seemed strange to me that regular expressions are described in the literature as string generators, yet I've pretty much only ever seen them used as string acceptors in practice in the form of a predicate (s in set <REGEX>?).