re-template-tag
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/re-template-tag package

2.0.1 • Public • Published

re-template-tag: easily compose regular expressions

This package provides the template tag re for composing regular expressions.

Basic syntax

Syntax: the following two expressions produce the same regular expression.

re`/abc/gu`
/abc/gu

Composing regular expressions

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

More information

Acknowledgement

The syntax for separating flags from the actual regular expression is based on an idea by Mathias Bynens.

Readme

Keywords

none

Package Sidebar

Install

npm i re-template-tag

Weekly Downloads

1,609

Version

2.0.1

License

MIT

Last publish

Collaborators

  • rauschma