I was just wondering if there is any free software out there that is able to effectively minimize regular expressions.
-
2Why would one need to "minimize" regular expressions? – Bergi Feb 09 '13 at 01:26
-
StackOverflow is not a software recommendation or location site. Google and Bing are both specialists in doing searches for things and returning links to the results of that search. (Searching for programs is also inappropriate here because it's not a programming question; it's a search for a software product, and that would be a question appropriate on [SuperUser](http://superuser.com).) Voting to close as off topic. – Ken White Feb 09 '13 at 01:27
-
3Searching for a program / algorithm / approach to minimizing RegEx is a better fit here than superuser. I agree the question is broad and definitely poorly framed, but disagree with the assessment of moving it or that it would be better answered elsewhere. – Matthew Feb 09 '13 at 01:30
-
How was my question poorly framed? – John Roberts Feb 09 '13 at 01:39
-
1@Bergi One would need to minimize regular expressions for the same reasons anyone needs to write code that is more succinct (though not necessarily faster). – John Roberts Feb 09 '13 at 01:43
-
@JohnRoberts Poorly framed was a strong term, but the wording of the request leads to an answer like Ken White gave (which I think was unwarranted). – Matthew Feb 09 '13 at 01:46
-
@JohnRoberts: However I think that is a task to be done by the programmer, not by a tool. I can write very concise code already, and if it gets shortened any much more it'll get completely incomprehensible. This should be especially true in the field of regular expressions, which are already hard to understand for the most people. – Bergi Feb 09 '13 at 01:49
-
1@Bergi I don't really understand why a programmer can't leverage a tool if it benefits his code to do so. In regards to your statement about comprehensibility, yes there is a fine line between succinctness and obfuscation, but this is not a priority for me, as this code is being written for my eyes only. – John Roberts Feb 09 '13 at 01:53
-
1@Matthew: Searching for a **library or algorithm** is a programming question, and is on-topic here. Searching for **software** (an application) is not. Software is an end-user product, and that's the type of question SuperUser is meant to answer, IMO. It's OK that you don't agree. :-) – Ken White Feb 09 '13 at 04:36
-
@KenWhite I don't think most people agree with your definition of "software". It definitely includes libraries, at least according to Wikipedia, Merriam-Webster, and the FSF. Perhaps you're thinking of "program"? – Ken Williams Jan 24 '15 at 04:43
-
@KenWilliams: Wow, I've heard of being nit-picking, but to post a comment on a nearly two year old question to quibble over such a minor thing sets a new standard. The question clearly asks for a program, which is off-topic here. – Ken White Jan 24 '15 at 04:46
-
My point is that I think it's a worthwhile question and didn't deserve to be closed. And old questions aren't dead, I came to this page with the same question as @JohnRoberts but was disappointed to see people saying it's not worth answering. – Ken Williams Jan 24 '15 at 04:52
2 Answers
You see this question being asked a lot but I haven't seen an effective one anywhere. If you think though the logic required just to simplify something simple like character ranges in a character class - and the fairly low value of doing something like that I think the lack of these begins to make sense.
As another example, how do you remove unneeded groupings when you don't know how they might be used in a replacement string. I would think any simplification that could be achieved would be mostly superficial.
This guy wrote one in Haskell but didn't share: http://community.haskell.org/~ndm/resimplify/
(PS: I sort of lied - there is one effective Regex simplification tool... The mechanical turk that is Stack Overflow :)

- 9,851
- 4
- 46
- 77
-
-
Simplification can be done, and it's often useful. I worked for a long time on a simplification tool at a previous job, but unfortunately I'm no longer there and they own the code. =( The basic idea is that you can simplify parts of the NFA to turn them into DFAs that run much more efficiently. You do indeed usually have to stop at capture-group boundaries, though. – Ken Williams Jan 24 '15 at 04:46
I think I found one located here: http://regexvisualizer.apphb.com/?Regex=%28a%2Bb%2Bc%2B%29%2B%7Cabc&NfaSize=300&DfaSize=250#

- 5,885
- 21
- 70
- 124
-
3Doesn't seem to work with complex regex - and by complex I mean something like `[^\s\d+\-.,:;^\/]+(?:\^\d+(?:$|(?=[\s:;\/])))?(?:\/[^\s\d+\-.,:;^\/]+(?:\^\d+(?:$|(?=[\s:;\/])))?)*` – Domino Apr 02 '15 at 18:28
-