Optimal RegEx UUID with extra delimiters
I already found a question for UUID regexes here , but those expressions don't account for the missing metrics.
I came up with the following expression , but is there a better RegEx?
/\b([0-9a-f]{8}-?([0-9a-f]{4}-?){3}[0-9a-f]{12})\b/i
source to share
I assume it is optimal that you mean a shorter expression. I've simplified your regex to the following:
/[\da-f]{8}-?([\da-f]{4}-?){3}[\da-f]{12}/i
which you can see in action here .
I removed the outer brackets and \b
because everything was matched correctly without them. I was also able to shave off three characters by replacing [0-9a-f]
with [\da-f]
.
I originally had [0-F]
, but after studying the ASCII sequence, I figured out that there is a mapping
0123456789:;<=>?@ABCDEF
that includes some additional characters that we don't want to match.
In conclusion, my expression is synonymous with yours, but contains nine more characters.
source to share