Skip to content

Instantly share code, notes, and snippets.

@fdorantesm
Forked from bugventure/uuid.js
Created April 27, 2020 18:05
Show Gist options
  • Save fdorantesm/a17e3e81f8abd901142883debead999a to your computer and use it in GitHub Desktop.
Save fdorantesm/a17e3e81f8abd901142883debead999a to your computer and use it in GitHub Desktop.
UUID regex matching in node.js
function createUUID() {
return uuid.v4();
}
// version 4
// createUUID.regex = '^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-4[a-fA-F0-9]{3}-[89abAB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}$';
createUUID.regex = '^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$';
createUUID.is = function (str) {
return new RegExp(createUUID.regex).test(str);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment