regexmoji
regexmoji is an experimental module. Its main goal is to make regular expressions easier to read and maintain. Just like how in CoffeeScript, annotating regular expressions is possible (and I love that), with this plugin you can do this in vanilla JS. Also, a key advantage over CoffeeScript is that, it can also reduce repetition.
Usage
This is one of the most confusing email validation patterns i can find online:
/[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/g
With regexmoji, it can reduce to:
;
It became easier to read, and even entertaining! This is just like a RegExp equivalent of template literals. I wish they existed. However, even if they existed, they would look something like this:
RegExp`/(?:\.)*@(?:(?:)?\.)+(?:)?/g`
So I like this emoji approach better. Especially visually.
API
Basic usage:
let regex =
Shorthand:
let regex =
Custom, re-usable:
let rm = let regex1 = let regex2 =