Timeline for Readable regular expressions without losing their power?
Current License: CC BY-SA 3.0
35 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Aug 7, 2022 at 18:12 | comment | added | hyde | @AndyLester But that expression is indeed rather obfuscated, and I'd definitely flag it in code review. It could be fahrenheit = (9.0 / 5.0) * celsius + 32.0 or even fahrenheit = celsius.toFahrenheit() or whatever things the programming language in use might allow. | |
| Aug 7, 2022 at 17:09 | comment | added | Andy Lester | When people say regexes are unreadable, that's because they haven't learned how yet. To someone who hasn't learned any programming, f=(9/5)*c+32 is unreadable gibberish, too. We didn't emerge from the womb knowing how to read that. After you learn how to read and write regexes, they too will be as clear to you as f=(9/5)*c+32 is. | |
| Jun 4, 2020 at 19:13 | answer | added | Brad Gilbert | timeline score: 4 | |
| Nov 21, 2017 at 19:01 | comment | added | smci | "is there a write-read solution/alternative?" = "is there a legible alternative?" | |
| Nov 17, 2017 at 0:01 | comment | added | smci | @Kaz: it's easy to beat up on regexes. By definition any choice of punctuation symbol for grouping could be criticized; or if regexes simply didn't do subexpressions, they'd be much less powerful. What better alternative do you propose instead of parentheses? | |
| Feb 8, 2017 at 12:26 | answer | added | CodeMonkey | timeline score: 2 | |
| Oct 13, 2016 at 19:15 | answer | added | Parivar Saraff | timeline score: 11 | |
| Mar 11, 2016 at 4:46 | history | protected | gnat | ||
| Oct 1, 2015 at 8:31 | comment | added | damix911 | Not really a practical answer, but it may be useful to mention that the power of regular expression is exactly as that of a finite automaton. That is, regexes can validate/parse the same class of strings validated and parsed by finite automatons. Hence, a human readable representation of a regex should probably be able to quickly build a graph, and I believe most text-based language are really bad at it; that's why we use visual tools for such things. Have a look at hackingoff.com/compilers/regular-expression-to-nfa-dfa to get some inspiration. | |
| Apr 18, 2013 at 22:23 | comment | added | Erik Reppen | There is no long answer. It's just "comments." | |
| Apr 18, 2013 at 18:48 | history | notice added | user28988 | Needs detailed answers | |
| Apr 18, 2013 at 0:02 | answer | added | Brendan | timeline score: -2 | |
| Apr 17, 2013 at 21:02 | answer | added | yoniLavi | timeline score: 3 | |
| Apr 17, 2013 at 9:55 | vote | accept | hyde | ||
| Apr 16, 2013 at 15:38 | comment | added | SK-logic | @hyde, take a look at pegjs.majda.cz for a starter. You do not have to depend on a standard library when you can download something better in one click. I'm too lazy to write a real answer. | |
| Apr 16, 2013 at 13:59 | comment | added | hyde | @SK-logic Well, one being supported natively or by standard library, while other is not, is kind of a reason. But why don't you add an answer showing an example of PEG in action in a mainstream language, it would certainly fit within the question scope. | |
| Apr 16, 2013 at 12:46 | comment | added | SK-logic | PEGs are much more readable (and more powerful). It's 21st century, no reason to stick to regexps any more. | |
| Apr 16, 2013 at 8:16 | comment | added | hyde | @BenLee Named capture groups is a good catch, not mentioned in any answer yet as far as I can see. If you can turn that into a short answer with example, I can promise one upvote at least :). If you want to work with the regexp in the question, capture group names could be "hour", "min", "sec", "fracs", that's what they actually are meant to be. | |
| Apr 16, 2013 at 3:51 | comment | added | Kaz | Part of the problem is the regex language itself, and the bad historic choices in its design which are dragged along like baggage. In a sane language, grouping parentheses are purely a syntactic device to shape the parse tree. But in regex implemenations going back to Unix they have semantics: binding registers to subexpression matches. So then you need some more complicated, ugly brackets just to achieve pure grouping! | |
| Apr 15, 2013 at 20:46 | comment | added | Ben Lee | Two options to clean this up without actually breaking it into smaller pieces. Their presence or absence varies from language to language. (1) extended line regexes, where whitespace in the regex is ignored (unless escaped) and a single-line comment form is added, so you can break it out into logical chunks with indentation, line spacing, and comments. (2) named capture groups, where you can give a name to each parenthetical, which both adds some self-documentation, and automatically populates a hash of matches -- way better than either a numerically indexed array of matches or $N variables. | |
| Apr 15, 2013 at 19:08 | comment | added | TC1 | Reading / editing regexes is actually trivial if you know what they're supposed to capture. You might have heard of this rarely used feature of most languages called "comments". If you don't put one above a complex regex explaining what it does you'll pay the price later. Also, code review. | |
| Apr 15, 2013 at 18:57 | history | edited | gnat | CC BY-SA 3.0 | title clarified from question text |
| Apr 15, 2013 at 18:06 | answer | added | Nick P | timeline score: 9 | |
| Apr 15, 2013 at 16:32 | comment | added | wim | related thing on SO: stackoverflow.com/a/143636/674039 | |
| Apr 15, 2013 at 16:09 | history | edited | Caleb | CC BY-SA 3.0 | Fixed title for better searchability: regular -> regular |
| Apr 15, 2013 at 15:55 | review | Close votes | |||
| Apr 15, 2013 at 17:11 | |||||
| Apr 15, 2013 at 15:50 | comment | added | gnat | see also: Decent tool for building and testing regular expressions | |
| Apr 15, 2013 at 15:04 | answer | added | Bobson | timeline score: 83 | |
| Apr 15, 2013 at 14:54 | answer | added | user40980 | timeline score: 47 | |
| Apr 15, 2013 at 14:28 | answer | added | Xion | timeline score: 30 | |
| Apr 15, 2013 at 14:23 | answer | added | jk. | timeline score: 4 | |
| Apr 15, 2013 at 14:10 | answer | added | E. Jaep | timeline score: 14 | |
| Apr 15, 2013 at 13:54 | history | tweeted | twitter.com/#!/StackProgrammer/status/323796576982142976 | ||
| Apr 15, 2013 at 12:52 | answer | added | Kilian Foth | timeline score: 16 | |
| Apr 15, 2013 at 12:44 | history | asked | hyde | CC BY-SA 3.0 |