Skip to content

Instantly share code, notes, and snippets.

@luisenriquecorona
Last active July 21, 2019 07:38
Show Gist options
  • Save luisenriquecorona/5f80173e988c86d2b2a12ced8930bdb3 to your computer and use it in GitHub Desktop.
Save luisenriquecorona/5f80173e988c86d2b2a12ced8930bdb3 to your computer and use it in GitHub Desktop.
ES6
function getFlags(re) {
var text = re.toString();
return text.substring(text.lastIndexOf("/") + 1, text.length);
}
// toString() is "/ab/g"
var re = /ab/g;
console.log(getFlags(re)); // "g"
let re = /ab/g;
console.log(re.source); // "ab"
console.log(re.flags); // "g"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment