News for hackers. Stuff that matters.
Re:Regular Expressions – Mastering Lookahead and Lookbehind by jstarfish on Thursday March 15, 2018 @11:52PM (#16598492)
They're definitely useful, and I can cobble them together to get lots of otherwise tedious and complex parsing tasks done, but when I come back to them a week later I have no idea what the hell the pile of wingding vomit I wrote was supposed to do.

I find myself writing simpler ones and tying them together with app code just for sanity's sake.

Re:Regular Expressions – Mastering Lookahead and Lookbehind by TeMPOraL on Friday March 16, 2018 @01:55AM (#16598926)
Some regex implementations allow for comments in the string; if your does not, you can probably make it work with concatenation, like:

  String pattern = "^https+" // match the protocol at the beginning
                 + "([a-zA-Z])+" // match the machine name
                 + ...
Honestly, I use regular expressions because, even in such format expanded with comments, I haven't seen anything more readable after you get used to regex operators. I guess the closest would be the alternative format in CL-PPCRE. For instance:

  CL-USER> (cl-ppcre:parse-string "\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\b")
  (:SEQUENCE :WORD-BOUNDARY (:GREEDY-REPETITION 1 3 :DIGIT-CLASS) #\.
   (:GREEDY-REPETITION 1 3 :DIGIT-CLASS) #\.
   (:GREEDY-REPETITION 1 3 :DIGIT-CLASS) #\.
   (:GREEDY-REPETITION 1 3 :DIGIT-CLASS) :WORD-BOUNDARY)
But then, any such form can get mouthful:

  CL-USER> (cl-ppcre:parse-string "((\\b[0-9]+)?\\.)?\\b[0-9]+([eE][-+]?[0-9]+)?\\b")
  (:SEQUENCE
   (:GREEDY-REPETITION 0 1
    (:REGISTER
     (:SEQUENCE
      (:GREEDY-REPETITION 0 1
       (:REGISTER
        (:SEQUENCE :WORD-BOUNDARY
         (:GREEDY-REPETITION 1 NIL (:CHAR-CLASS (:RANGE #\0 #\9))))))
      #\.)))
   :WORD-BOUNDARY
   (:GREEDY-REPETITION 1 NIL (:CHAR-CLASS (:RANGE #\0 #\9)))
   (:GREEDY-REPETITION 0 1
    (:REGISTER
     (:SEQUENCE (:CHAR-CLASS #\e #\E)
      (:GREEDY-REPETITION 0 1 (:CHAR-CLASS #\- #\+))
      (:GREEDY-REPETITION 1 NIL (:CHAR-CLASS (:RANGE #\0 #\9))))))
   :WORD-BOUNDARY)
Re:Regular Expressions – Mastering Lookahead and Lookbehind by arkh on Friday March 16, 2018 @04:21AM (#16599323)
If you're using PCRE you should also make use of named patterns. It makes the expression easier to understand as you can reuse parts of it (a little like functions) and the matched patterns can be then used in your language with their name instead of their position. Decoupling the usage from the regexp so it is more robust.

http://www.rexegg.com/regex-capture.html#namedgroups

Re:Regular Expressions – Mastering Lookahead and Lookbehind by reificator on Friday March 16, 2018 @03:08PM (#16603191)
That would be nice to have when working in Javascript, making code a lot more readable and easy to update.

Alas, we don't get such luxuries as named groups or static typing... Woe is me.

Re:Regular Expressions – Mastering Lookahead and Lookbehind by dash2 on Friday March 16, 2018 @04:42AM (#16599377)
I wonder if Perl 6 regexes and grammars might show a way forward for more readable pattern matching.
Re:Regular Expressions – Mastering Lookahead and Lookbehind by b2gills on Wednesday March 21, 2018 @05:45PM (#16642709)
An example would be helpful so here is one https://github.com/moritz/json/blob/master/lib/JSON/Tiny/Gra...
Re:Regular Expressions – Mastering Lookahead and Lookbehind by testestx on Friday March 16, 2018 @01:24AM (#16598821)
> I find myself writing simpler ones and tying them together with app code just for sanity's sake.

Or just use PEG, parser combinators, or other more readable parsing abstractions