News for hackers. Stuff that matters.
Re:ReX.js – Your RegEx companion by dymk on Monday November 19, 2018 @05:03PM (#18490133)
Let me save you 8 kilobytes of dependency and a new API to learn (and debug, when you start wondering why your ReX built regex isn't working how you want). Apparently the main "feature" of ReX is you get to annotate the components of a regex string.

    // match something that looks like a date in the form 02-14-1924
    let x = "";
    x += '\d{2}'; // match the month 
    x += '\-';
    x += '\d{2}'; // match the day
    x += '\-';
    x += '\d{4}'; // match the year
Even this is horribly overcomplicated example would just be `\d{2}\-\d{2}\-\d{4}`. The Rex library provides no useful abstractions to simplify vanilla javascript and regex.

If a (dynamically built) regex misbehaves, I'm only inspecting the lines of code that compose the string, not an entire library to understand what went wrong.

Re:ReX.js – Your RegEx companion by kbd on Monday November 19, 2018 @05:43PM (#18490405)
No need to escape the dashes btw:

    $ node
    > '02-14-1924'.match(/\d{2}-\d{2}-\d{4}/)
    [ '02-14-1924', index: 0, input: '02-14-1924', groups: undefined ]
Re:ReX.js – Your RegEx companion by bmn__ on Monday November 19, 2018 @06:22PM (#18490610)
That's poor usage of regex. Try this:

    $ node
    > let XRegExp = require('xregexp');
    > XRegExp.exec('02-14-1924', XRegExp(`
        (?<day>  \\d{2} ) -
        (?<mon>  \\d{2} ) -
        (?<year> \\d{4} )
    `, 'x'))
    [ '02-14-19',
      '02',
      '14',
      '1924',
      index: 0,
      input: '02-14-1924',
      groups: undefined,
      day: '02',
      mon: '14',
      year: '1924' ]