Skip to content

Instantly share code, notes, and snippets.

@vsemozhetbyt
Created July 21, 2017 23:51
Show Gist options
  • Save vsemozhetbyt/332725c1ba80d5da82e550ff46b7dd74 to your computer and use it in GitHub Desktop.
Save vsemozhetbyt/332725c1ba80d5da82e550ff46b7dd74 to your computer and use it in GitHub Desktop.
RegExp tag function with flags
'use strict';
function re(strings, ...expressions) {
const pattern = expressions.reduce(
(acc, expr, i) => `${acc}${expr}${strings[i + 1]}`, strings[0]
);
return ([flags]) => new RegExp(pattern, flags);
}
console.log(re`^abc$``gu`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment