4 ms·
My CS honours thesis involved deriving regexes (well, DTDs for XML documents, but it is essentially the same problem). The quality of the results depends a lot
by jsankey 16y ago
My CS honours thesis involved deriving regexes (well, DTDs for XML documents, but it is essentially the same problem).
The quality of the results depends a lot on the amount and quality of the input (how well it represents what you are really trying to match). A single example string is unlikely to get you far - you would certainly need multiple matching examples. So I think this approach works best when you already have an example corpus to work from, rather than providing input manually. If you're going to spend effort providing a lot of input, then you'd probably be better off spending at least some of that effort in providing hints or possible regex answers.
Further, there are many possible regexes that would match an input set, so the algorithm also needs some way to evaluate them and choose the better candidates. In my case I used some ideas from information theory (such as MML), which actually worked reasonably well. But this is a computationally hard problem, so even with an objective measure of the optimal regex you won't necessarily be able to find it.