3 ms·
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). Appa
by dymk 8y ago
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.
- kbd 8y agoNo 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 ]
- bmn__ 8y agoThat'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' ]