3 ms·
"I am not much of a fan of RegularExpressions. It is too hard to remember what the symbols stand for, for one. Asterisk for 0 or more repetition, plus for 1 or
by Retra 11y ago
"I am not much of a fan of RegularExpressions. It is too hard to remember what the symbols stand for, for one. Asterisk for 0 or more repetition, plus for 1 or more repetitions, question mark for 0 or 1 occurrences, brackets surrounding a set of characters -- who's got time to memorize this kind of complexity? "
Somebody please tell me this is sarcasm...
- jedmeyers 11y ago= for equals, or assign, or compare, < for less, > for more, + for adding, - for subtracting -- who's got time to memorize this kind of complexity?
- a1369209993 11y agoTechnically, compare is ==. = means "trash the left argument, then interpret the the right argument as a boolean". :)
- jqm 11y agoHis examples were bad (asterisk etc.) but the point is valid. There is some hairy regular expression syntax that is pretty difficult to grok right off the bat. It could be simpler and clearer.
- Retra 11y agoYou could say that about any syntax. But actually coming up with a better syntax is much harder than just saying it can be done.
- jqm 11y agoYou could say that about any syntax. But in most cases it would still apply much more to things like Perl regular expressions.
- vezzy-fnord 11y agoThere's VerbalExpressions, which simply wrap common PCRE tokens into methods/functions: https://github.com/VerbalExpressions https://github.com/VerbalExpressions
- Retra 11y agoThose are pretty good, if a little verbose.
- toufique 11y agoThis is awesome, like life-changing awesome! I always felt an impedance mismatch between how my mind describes string patterns and how regexps are written. VerbalExpressions is the closest thing I've seen to how I naturally think.
- techdragon 11y agoThis is going to rapidly replace every instance of regex in my code. The readability improvement is immeasurable. It's also conveniently similar enough to Python's verbose regex syntax.
- ivanhoe 11y agoNo one forces you to memorize every possible mnemonic, you remember the basic stuff that you use all the time, than you learn a bit more when you need it. And there is google for the rest, just like with everything else. And I seriously doubt that it could be made simpler and clearer for everyone, because we all come from different backgrounds and work on different things and our brains are by now hardwired to quickly handle different syntaxes. So it is a huge undertaking to rewrite something as complex as regexp to a completely new syntax and yet clearer and simpler to the majority of devs. Which of course doesn't mean one shouldn't try...
- jacobolus 11y agoRegular expressions are a very obviously inefficient and confusing syntax, full of incidental complexity, and to make matters worse, they’re often a bit less powerful than we want them to be. The best summary of the problems I’ve seen is from Larry Wall, highly recommended if you haven’t read it before. First half of this page: http://perl6.org/archive/doc/design/apo/A05.html http://perl6.org/archive/doc/design/apo/A05.html Unfortunately, I think at this point regular expressions are too firmly entrenched in too many places to properly replace.
- masukomi 11y agoThey are not obviously inefficient and confusing. Many of us, especially the Perl geeks, find them relatively clear when well written. It's a mini language, and like any language it can be clear or opaque in its meaning depending on the skill and intention of the creator.
- raiph 11y agoFrom the preamble of the page you linked: > In fact, regular expression culture is a mess, and I share some of the blame for making it that way. Since my mother always told me to clean up my own messes, I suppose I'll have to do just that. So Larry aimed to do better in Perl 6. Do you think he is as good at solving problems as he is at identifying them -- or more specifically, what do you think of the "Rules" system[1] he came up with for Perl 6? [1] https://en.wikipedia.org/wiki/Perl_6_rules https://en.wikipedia.org/wiki/Perl_6_rules
- amenghra 11y agoThe main issue I have with regular expressions is that the current syntax mixes "code" and "data". I.e. it's very easy to write something like /https?:\/\/www.foo.com/ (e.g. you want to whitelist your own domain for some action) and forget that this also matches wwwxfoo.com which could be owned by anyone (it's also a common mistake to forget the anchors, in this case evil.com/?https://www.foo.com https://www.foo.com might also match). It is pretty easy to come up with a better syntax, but it's going to be hard to convince everyone to use it. As someone else commented on this thread, the current way of doing things is pretty entrenched.