4 ms·
This first thing I tried to do was [\d]+ But it didn't work. Took me a few tries to get it to work. I'm guessing it simply doesn't work with special regex c
by JangoSteve 16y ago
This first thing I tried to do was
[\d]+
But it didn't work. Took me a few tries to get it to work. I'm guessing it simply doesn't work with special regex characters.
You know what would be even more useful for me? I give you a string and highlight the important part I need to match, and you give me a good regex for it.
Example: I need to match the string "View conversation (5)", with the important part being that there is a number near the end of the string. So I type that and highlight the "5". Then you give me something like:
/[^\d]+\d+[^\d]*/
Or whatever. Obviously it won't be full-proof because you don't know all my use cases and edge cases, but it'd give me somewhere to start.
- rndmcnlly0 16y agoI've thought about how to do a kind of regex-induction, where you give it matches and it gives you one or more expressions that will match it. But, after some thinking, even with a reasonable language bias, getting useful expression comes down to getting the user to type in a collection of positive an negative match examples. This kind of tool would be really nice to use, but the interaction has to be more than giving a single positive example. A an iterative process where you start from a single positive example and then iteratively refine it with clarifying examples would work without being overwhelming. However, I'm really trying to get the user to better understand regexes to the point where they could do that process for themselves, mentally, and not depend on a super intelligent tool to do it for them.
- jsankey 16y agoMy 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.