News for hackers. Stuff that matters.
Re:The New ‘Absent Operator’ in Ruby’s Regular Expressions by viggity on Thursday March 23, 2017 @10:52AM (#13940206)
i'm a huge regex nerd (see: regexpixie.com). But this is a classic example of people trying to be clever instead of clear. And I would always much prefer to read clear code than clever code.

Regexes are declarative and they're really good a narrow set of features - namely, finding text that matches a pattern. When I see someone using negative/positive lookaheads, or trying to match a valid date with a regex, I see someone who is furiously pounding a nail with the fat end of a screwdriver.

If you want to keep things simple with regular expressions:

* Be liberal with what your pattern matches and use a normal programming language for your complicated conditional logic to filter out crap you don't want

* Don't be afraid to break up the search with multiple regular expressions

* Ignore pattern whitespace and use it to visually break up your pattern. Nobody would agree to debug javascript that has been minimized, yet people do this all the time with regex

* For the love of all that is holy, USE NAMED GROUPS. It is a fantastic way to document your intent.

This is confusing: \d{1,2}/\d{1,2}/(\d{4}|\d{2})

This is not:

(?<day>\d{1,2})

/

(?<month>\d{1,2})

/

(?<year>\d{4}|\d{2})

Re:The New ‘Absent Operator’ in Ruby’s Regular Expressions by petercooper on Thursday March 23, 2017 @11:25AM (#13940555)
Have you considered doing a sort of regex best practices post? I'd be happy to promote such a thing or even help get it out. I think a lot of people want that sort of info.
Re:The New ‘Absent Operator’ in Ruby’s Regular Expressions by falsedan on Friday March 24, 2017 @09:56AM (#13948905)
If I wrote a post, it would be: "read Ch. 12 of Perl Best Practices (2005)[0]".

Yow, $30+ for the ebook! I wouldn't buy if just for that chapter… fortunately, the guidelines from the book have been codified as Perl::Critic, so If you don't mind missing out on the gently guiding text which accompanies each rule, you can browse the Perl::Critic::Policy::RegularExpressions[1] submodule docs.

[0]: http://shop.oreilly.com/product/9780596001735.do [1]: https://metacpan.org/pod/Perl::Critic::Policy::RegularExpres...

Re:The New ‘Absent Operator’ in Ruby’s Regular Expressions by rntz on Thursday March 23, 2017 @11:01AM (#13940303)
This isn't about negative lookaheads or lookbehinds. It's about negation proper. It is perfectly declarative: the language matched by (?~E) is the complement of the language matched by E.
Re:The New ‘Absent Operator’ in Ruby’s Regular Expressions by brudgers on Thursday March 23, 2017 @01:50PM (#13942185)
I've found trying to point out the differences between regular expressions as finite automata and regular expressions as a reference to the regex|regexp constructs within programming languages difficult, and have given it up as a hobby.

The programming language constructs are useful in many cases but harder to reason about. The finite automata are easier to reason about but limit themselves to state machines. Here the complexity is that the operator operates in the state-machine space wrapped up inside the programming language construct.

Ok, so I guess I did not give it up as a hobby.