Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tenbits/ec7f0155b57b2d61a6cc90ef3d5f8b49 to your computer and use it in GitHub Desktop.
Save tenbits/ec7f0155b57b2d61a6cc90ef3d5f8b49 to your computer and use it in GitHub Desktop.
Not sure that serialization "works"
var x = new RegExp( "/" )
console.log(x.test( "/hello" ));
var serializedRegexParser = /^\/(.+)\/(\w+)?$/
var serializedRegex = x.toString();
console.log('serializedRegex:', serializedRegex);
var matches = serializedRegexParser.exec(serializedRegex);
var [full, regexString, regexFlags] = matches;
console.log('regexString:', regexString);
var y = new RegExp(regexString, regexFlags);
console.log(y.test( "/hello" ));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment