Created
July 30, 2019 06:42
-
-
Save KrofDrakula/f0ee95147ed0e8f5cb2bd5456e63ae3b to your computer and use it in GitHub Desktop.
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
const SPECIAL_CHARS = /[-\/\\^$*+?.()|[\]{}]/g; | |
const ESCAPED_CHAR = "\\$&"; | |
const escapeRegExp = (s: string) => s.replace(SPECIAL_CHARS, ESCAPED_CHAR); | |
const regexp = (flags?: string) => | |
(strings: string[], ...values: string[]) => | |
new RegExp(strings[0] + values.map((value, index) => escapeRegExp(value) + strings[index + 1]).join(""), flags); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment