Last active
September 30, 2018 20:41
-
-
Save Raiondesu/eb3dfb5b9a14e5e944fb882c400ffd47 to your computer and use it in GitHub Desktop.
A simple function that parses a JS regular expression from a string
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
export default strRegExp => { | |
const flags = strRegExp.replace(/.*\/([gimy]*)$/, '$1'); | |
const pattern = strRegExp.replace(new RegExp('^/(.*?)/'+flags+'$'), '$1'); | |
return new RegExp(pattern, flags); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment