Skip to content

Instantly share code, notes, and snippets.

@Raiondesu
Last active September 30, 2018 20:41
Show Gist options
  • Save Raiondesu/eb3dfb5b9a14e5e944fb882c400ffd47 to your computer and use it in GitHub Desktop.
Save Raiondesu/eb3dfb5b9a14e5e944fb882c400ffd47 to your computer and use it in GitHub Desktop.
A simple function that parses a JS regular expression from a string
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