Last active
September 5, 2022 14:14
-
-
Save awesome/020dcdc66b177ca4b5b8619c575ecfdd to your computer and use it in GitHub Desktop.
UUID pure regexp and dash/hyphen is optional; return only full uuid matched
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
# https://ihateregex.io/expr/uuid/ | |
/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/ | |
# https://rubular.com/r/sXJ27X08h7tKZ2 refactor by soawesomeman | |
/([0-9a-fA-F]{8}-?(?:[0-9a-fA-F]{4}-?){2}[0-9a-fA-F]{4}-?[0-9a-fA-F]{12})/ | |
# https://rubular.com/r/lIO6HeHPlHcTl3 further refactor by soawesomeman | |
# see: https://stackoverflow.com/questions/15205896/matching-any-character-except-an-underscore-using-regex#15206584 | |
/((?:(?!_)[\w\d]){8}-?(?:(?:(?!_)[\w\d]){4}-?){3}-?(?:(?!_)[\w\d]){12})/ | |
# https://rubular.com/r/PFrxaj9h9GZRPX further refactor by soawesomeman | |
# scope to word boundary with `\b` | |
/\b((?:(?!_)[\w\d]){8}-?(?:(?:(?!_)[\w\d]){4}-?){3}-?(?:(?!_)[\w\d]){12})\b/ | |
# https://rubular.com/r/mjHJuRzi050p41 further refactor by soawesomeman | |
# digits included in `\w`; removed `\d` | |
\b((?:(?!_)\w){8}-?(?:(?:(?!_)\w){4}-?){3}-?(?:(?!_)\w){12})\b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
while we're on the subject…