Created
July 21, 2017 23:51
-
-
Save vsemozhetbyt/332725c1ba80d5da82e550ff46b7dd74 to your computer and use it in GitHub Desktop.
RegExp tag function with flags
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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