This package provides the template tag `re` for composing regular expressions.
npm install re-template-tagThis package provides the template tag re for composing regular expressions.
Syntax: the following two expressions produce the same regular expression.
``js/abc/gu
re`
/abc/gu
`js
import {re} from 're-template-tag';
const RE_YEAR = /([0-9]{4})/;
const RE_MONTH = /([0-9]{2})/;
const RE_DAY = /([0-9]{2})/;
const RE_DATE = re/^${RE_YEAR}-${RE_MONTH}-${RE_DAY}$/u;
RE_DATE.test('2017-01-23'); // true
``
* Take a look at the unit tests.
* Check out the blog post on re-template-tag.
The syntax for separating flags from the actual regular expression is based on an idea by Mathias Bynens.