Automatic Generation of Regular Expressions from Examples
regex.inginf.units.it
regex.inginf.units.it
We simply did not expect so much interest in our work. Yesterday we received more than 11000 visits. We are not prepared to handle such traffic.
We are working toward adding a few more CPUs and will notify the status on our Twitter account: http://twitter.com/@MaleLabTs.
We are afraid we will not be able to fully solve the overload problem anytime soon, though. We are a small research group, with scarce resources.
We are also preparing a small faq for addressing several of the interesting points raised in this discussion (e.g., why not executing everything in Javascript ?). We will notify completion via Twitter. Further comments and criticisms are most welcome.
Thanks a lot for your interest and patience.
Apologies for the extreme load caused - when geeks find something cool they tend to share it, and not everyone is ready for that level of interest.
I, for one, look forward to your updates. What would be really great would be for you to prepare some kind of informal overview and put that up as a blog post, making it clear that it's intended to be informal, and is not in any way your formal research results or anything like that. Then post here a link to it. If you engage with this community you'll get a lot of smart people offering thoughts and suggestions from which you can pick and choose.
Great work - thank you.
(?:\d\d[\d\d\.\d\.][\d\.](?:(?=([\d\.]+))\1))
"[\d\d\.\d\.]" is equivalent to "[\d\.]", right?It's also got a useless non-capturing group and lookahead.
These regex's are generated with genetic programming techniques, so they are not guaranteed to be an optimal solution, just a good (by the metric of working) one.
Applying some fairly simple optimizations to my example result I get the following equivalent regular expression:
\d{2}[\d\.]{3,}
which isn't too bad.EDIT: Here are the optimizations:
The original:
(?:\d\d[\d\d\.\d\.][\d\.](?:(?=([\d\.]+))\1))
1. Remove non-capturing groups and lookahead: \d\d[\d\d\.\d\.][\d\.]([\d\.]+)\1
2. Simplify set: \d\d[\d\.][\d\.]([\d\.]+)\1
3. Remove redundant backreference: \d\d[\d\.][\d\.][\d\.]+
4. Combine duplicates: \d{2}[\d\.]{3,}Putting it another way, your highly optimized version (4) is likely to be much more brittle to small 'defects' than (1).
For example, given training data 000001 000002 000003 000004
The "optimized" version would be \d+[1-4]
If the goal was simply to find the smallest regex that matches all the training data, that's trivial to code, NP-hard to execute.
But the goal isn't to find the smallest regexp, it's to find a "good" regexp.
I also wasn't trying to say those simplifications should be applied between iterations of the algorithm, only at the end.
Not only are the expressions tending to get more accurate with each generation, but their degree of 'evolvability' is also being selected for.
- find "small" regex that defines the language for the example — hard problem
- minimize the regex (the language stays the same) — can be solved efficiently
See the link from http://news.ycombinator.com/item?id=4682623Why divide the data into sets like that? Assuming the sample data is representative, wouldn't it be better to use much more for training, say 90% with 10% for validation?
See here for example: http://en.wikipedia.org/wiki/Overfitting
[1]: http://en.wikipedia.org/wiki/Cross-validation_%28statistics%...
Edit: you.get.it
Note that there are other (non-genetic) approaches to learn regular expressions (some are cited in the above paper).
It would be interesting for me and others here to learn from what you know rather than be left with what you wrote.
This is something I would have found useful a year or two ago, considered writing, and decided it would be impossible to get a usefully generalised regex. I'm glad people cleverer and less defeatist than me had the same idea, since it seems it is possible to get useful results after all :)
It is actually a text editor, and doesn't come up with Regular Expressions but similar textual constraint patterns.
The real problem is that the space of possible solutions is very large, so you will have to do that lazily, which would make an implementation in a lot of languages rather annoying.
I'd also expect this algorithm to be biased towards regular expressions that are more specific than the user intended them to be, especially for example sets that are small or not very diverse.
Ah, no, looking at your profile you haven't yet ever shared a link. I can only conclude that you find lots and lots of things that you are eager to share with us, but when you rigorously test them you find that they can't handle the load, so you sadly decline to submit them.
Thanks for the feedback. I'll be sure to keep it in mind.
(Nice ad hominem, by the way.)
How can one tell if the server is going to be able to handle the load? Perhaps the owners had anticipated that this would be of interest and were ready to handle it?
How could I tell?
I think it's a reasonable expectation in a community of geeks that if you are to level criticism at me, then you should offer alternatives and constructive suggestions, and I look forward to your reply as to what one should do when considering submitting a link like this.
How would you test it?
Honestly, I'm a bit dismayed that you are challenging me on this. "Load-test your code before releasing it" should be a strict requirement for anything that is submitted here. Otherwise, how are people expected to give feedback? Why is our time being wasted on stuff that does not work?
You do realize, do you not, that it's not my code. Or my server. I'm just sharing something I found.