I am assuming by optimal that you mean a shorter expression. I simplified your regex down 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 parentheses and \b
because everything was correctly matched without them.
I was also able to shave three characters off by replacing [0-9a-f]
with [\da-f]
.
I originally had [0-F]
, but after examining the ASCII sequence, I realized that matched
0123456789:;<=>?@ABCDEF
, which includes some extra symbols that we do not want to match.
In conclusion, my expression is synonymous with yours but contains nine fewer characters.